Meaningless Drivel is fun!*
The moose likes Other Application Frameworks and the fly likes JSP views rendering 0 bytes and HTTP 200 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "JSP views rendering 0 bytes and HTTP 200" Watch "JSP views rendering 0 bytes and HTTP 200" New topic
Author

JSP views rendering 0 bytes and HTTP 200

Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
[DISCLAIMER: This is a duplicate for a question I posted in the official forums but haven't received any replies yet]

I've got a weird problem I haven't been able to figure out.

Using the following viewResolver configuration renders a pretty Velocity template:

For example, new ModelAndView("foo") renders the template from /WEB-INF/velocity/foo.vm.

However, when I tried to create a similar configuration for rendering JSP's (and commented out the Velocity stuff), I'm getting a HTTP 200 with no content at all.

Trying to access the URL http://localhost:8080/myapp/foo.html (I've mapped the DispatcherServlet to "*.html") results in the following log output:

What wonders me is that the log clearly claims the request was forwarded to "/WEB-INF/jsp/list.jsp" but the JSP is never rendered. Instead, as I mentioned already, I get 0 bytes of content and a HTTP 200 response code.

Here's the web.xml stuff that maps the request to the controller:


Any help is obviously appreciated. Especially if it makes me slap my forehead ;-)
[ October 10, 2005: Message edited by: Lasse Koskela ]

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

The first thing I'd try is to remove the jsp from the WEB-INF directory, just to be sure. Ben will disagree, but I've seen some weird behaviour trying this that has con vinced me not to do it.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Thanks for the tip, although I have tried putting my JSP's both in "/*.jsp" as well as "/jsp/*.jsp" and "/WEB-INF/jsp/*.jsp" -- all with the same result.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

More stuff which is really just sanity checks:

* add some logging to the JSP to see if it is executing at all. While I can't believe it would parse the file then omit the output without an error, I can imagine it.
* It may be stale, try deleting all of your compiled JSPs.

I'm trying to think of something in Spring which may create this effect, but my experience doesn't go deep enough. If you use Log4J and turn it onto DEBUG you'll get more information than you'll ever need.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by David O'Meara:
* add some logging to the JSP to see if it is executing at all. While I can't believe it would parse the file then omit the output without an error, I can imagine it.
* It may be stale, try deleting all of your compiled JSPs.

I did try adding the classic System.out.println and it doesn't say anything. In other words, the JSP doesn't seem to get invoked at all.
I didn't try to delete the working directories, although I think the build script might be creating a clean copy of the Tomcat "/work" directory (I'm using Cargo's Ant tasks).

Originally posted by David O'Meara:
I'm trying to think of something in Spring which may create this effect, but my experience doesn't go deep enough. If you use Log4J and turn it onto DEBUG you'll get more information than you'll ever need.

The output I posted above is actually from the DEBUG level. I just ripped away the "excess" information to make it fit even somehow on the screen

Thanks again. I'll report back whether deleting the compiled JSP's will help.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

You should be able to safely delete the contents of the 'work' directory. (not the directory itself, just the contents.) From memory System.out won't work in Tomcat, it just gets lost, but I may be wrong.

My contact with Spring was fairly light, allowing us to abstract Hibernate and manage the usual transaction stuff, hence I'm treating this as a JSP problem
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Also, while I'm racking my brain for strange behaviour:

Check the source returned and search for any content from the JSP, even if is not where you expected it to be. I've seen threading problems before where output was being returned but treated as 'white space' by the browser since its response was not synchronised with the other parts. Strange but true.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Originally posted by David O'Meara:
From memory System.out won't work in Tomcat, it just gets lost, but I may be wrong.
It works at least from Servlets (in Tomcat 5.5). Hmm. Maybe I should try putting System.exit() into the JSP and see what happens

Originally posted by David O'Meara:
Check the source returned and search for any content from the JSP, even if is not where you expected it to be. I've seen threading problems before where output was being returned but treated as 'white space' by the browser since its response was not synchronised with the other parts. Strange but true.

Ah. I actually tried wget which reported zero bytes downloaded.
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Sorry. I forgot to post here that I eventually solved the problem by downgrading from Tomcat 5.5.9 to 5.0.28. Don't know what made the difference and didn't even try to find out.

On 5.0.28 everything works smoothly -- the same code, the same configuration, everything.
 
 
subject: JSP views rendering 0 bytes and HTTP 200
 
Similar Threads
How Spring loads spring configuration files ?
Spring weblflow
[SOLVED] images fail to load in spring2.5/tiles2
Hibernate transaction begin stuck
Problem in spring sample application