Announcement Announcement Module
Collapse
No announcement yet.
JSP views rendering 0 bytes and HTTP 200 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JSP views rendering 0 bytes and HTTP 200

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

    Using the following viewResolver configuration renders a pretty Velocity template:
    Code:
    <bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
    		<property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
    	</bean>
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
    		<property name="cache" value="true"/>
    		<property name="prefix" value=""/>
    		<property name="suffix" value=".vm"/>
    	</bean>
    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.
    Code:
    	<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    		<property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
    		<property name="prefix"><value>/WEB-INF/jsp/</value></property>
    		<property name="suffix"><value>.jsp</value></property>
    	</bean>
    Trying to access the URL http://localhost:8080/myapp/foo.html (I've mapped the DispatcherServlet to "*.html") results in the following log output:
    Code:
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Testing handler map &#91;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping@5a67c9&#93; in DispatcherServlet with name 'app'>
    &#91;org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping&#93; - <Looking up handler for &#91;/list.html&#93;>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Testing handler adapter &#91;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@153c375&#93;>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Last-Modified value for &#91;/myapp/list.html&#93; is &#91;-1&#93;>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <DispatcherServlet with name 'app' received request for &#91;/myapp/list.html&#93;>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Testing handler adapter &#91;org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter@153c375&#93;>
    &#91;org.springframework.web.servlet.view.InternalResourceViewResolver&#93; - <Cached view 'list'>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Rendering view &#91;org.springframework.web.servlet.view.JstlView&#58; name 'list'; URL &#91;/WEB-INF/jsp/list.jsp&#93;&#93; in DispatcherServlet with name 'app'>
    &#91;org.springframework.web.servlet.view.JstlView&#93; - <Rendering view with name 'list' with model &#123;list=&#91;First, Second, Third&#93;&#125; and static attributes &#123;&#125;>
    &#91;org.springframework.web.servlet.view.JstlView&#93; - <Added model object 'list' of type &#91;java.util.ArrayList&#93; to request in InternalResourceView 'list'>
    &#91;org.springframework.web.servlet.view.JstlView&#93; - <Forwarded to resource &#91;/WEB-INF/jsp/list.jsp&#93; in InternalResourceView 'list'>
    &#91;org.springframework.web.servlet.DispatcherServlet&#93; - <Successfully completed request>
    &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; - <Publishing event in context &#91;WebApplicationContext for namespace 'app-servlet'&#93;&#58; RequestHandledEvent&#58; url=&#91;/myapp/list.html&#93;; time=&#91;871ms&#93;; client=&#91;127.0.0.1&#93;; method=&#91;GET&#93;; servlet=&#91;app&#93;; session=&#91;null&#93;; user=&#91;null&#93;; status=&#91;OK&#93;>
    &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; - <Publishing event in context &#91;Root WebApplicationContext&#93;&#58; RequestHandledEvent&#58; url=&#91;/myapp/list.html&#93;; time=&#91;871ms&#93;; client=&#91;127.0.0.1&#93;; method=&#91;GET&#93;; servlet=&#91;app&#93;; session=&#91;null&#93;; user=&#91;null&#93;; status=&#91;OK&#93;>
    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:
    Code:
      <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>*.html</url-pattern>
      </servlet-mapping>
    Any help is obviously appreciated. Especially if it makes me slap my forehead ;-)

  • #2
    Do you receive this same error for all jsps?

    Comment


    • #3
      Well, I only had 2 JSP's at the time -- an index.jsp which redirected to a URL mapped to a controller, which would then forward the request to the other JSP. It was that other JSP that wasn't rendering anything (i.e. not executing at all).

      I have to apologize, though. I eventually solved the problem by downgrading from Tomcat 5.5.9 to 5.0.28 on which everything works smoothly -- the same code, the same configuration, everything.

      Comment

      Working...
      X