3 Replies Latest reply on Jun 25, 2010 9:59 AM by ranjix

    request include attributes missing in the included jsp

    ranjix Newbie

      Hey guys, not sure if this is the right place or maybe I should just open a bug/issue/ticket with the Tomcat team itself. I might do that too.

       

      Anyway, I do have an issue with the dynamically include jsps. Let me see if I can describe this properly.

      I do have 2 jsp pages - page1.jsp, page2.jsp, and a filter which executes on every jsp request.

       

       

      page1.jsp

      ...

      <jsp:include page="page2.jsp">

      ...

       

      page2.jsp

      ...

       

      Filter:

       

      if (request.getAttribute("javax.servlet.include.request_uri") != null)...

       

      The issue here is that when the filter gets executed on the included jsp, the attribute is null. As far as I understand, based on the Servlet 2.5 spec, these attributes should be set.

       

       

      SRV.8.3.1 Included Request Parameters
      Except for servlets obtained by using the getNamedDispatcher method, a servlet that has been invoked by another servlet using the include method of RequestDispatcher has access to the path by which it was invoked. The following request attributes must be set:
      javax.servlet.include.request_uri
      javax.servlet.include.context_path
      javax.servlet.include.servlet_path
      javax.servlet.include.path_info
      javax.servlet.include.query_string
      These attributes are accessible from the included servlet via the getAttribute method on the request object and their values must be equal to the request URI, context path, servlet path, path info, and query string of the included servlet, respectively. If the request is subsequently included, these attributes are replaced for that include. If the included servlet was obtained by using the getNamedDispatcher method, these attributes must not be set.

       

      Kind of tracked the problem through Tomcat code, and the issue, as far as I understand, is in org.apache.catalina.core.ApplicationHttpRequest class, where there is a setAttribute method that DOESN'T add the attribute to the request if the attribute is "special" (and the javax.servlet.include attributes are special). If I modify the method a little to add the attribute regardless of how special the attribute is, then the code works fine. The other containers I'm working with (WebLogic, WebSphere), do add the attribute on the include.

       

      Any idea how come Tomcat is different, and, maybe even more important, how can I figure out in the filter executing on the include, if I'm in an included jsp or not? (the attribute check fails)...

       

      thanks/

      ranjix

        • 1. Re: request include attributes missing in the included jsp
          Jean-Frederic Clere Master

          That is normal the 2 jsp are one servlet once compiled aren't they?

          • 2. Re: request include attributes missing in the included jsp
            ranjix Newbie

            Thanks Jean, but no, they aren't. There are 2 java/classes, page1_jsp.class and page2_jsp.class (which I think is normal, since the <jsp:include> is a dynamic include). In any case, the problem is actually more complex, and I'm still testing. The extra complexity is some RequestWrapper around the Request which overrides the getAttribute and setAttribute from the parent (HttpServletRequestWrapper). Without the complexity (just sending directly the request through the chain, without wrapping it), the execution seems correct, the attributes javax.servlet.include.* get set and read correctly.

             

            So works correctly if I have

            - call to page1.jsp

              - goes through filter

                - filter calls chain (executes page1.jsp) with same original objects as request and response

                  - page1.jsp calls the include

                    - filter gets executed on page2.jsp - here if I output the javax.servlet.include attributes, they are set (which is good)

                      - filter calls again chain (page2.jsp) with the same original requests

                        - page2.jsp outputs the include attributes, which are set (which is good)

             

             

            The problem, until now, seems to be caused by the fact that I use a wrapper which overrides getAttribute and setAttribute, and the issue, in my opinion, is that the setAttribute is not being called, at all. It looks like Tomcat is using another wrapper around the request, and the setAttribute on mine doesn't get called.

             

            - call to page1.jsp

              - goes through filter

                - filter creates wrapper around the request

                - filter calls chain (executes page1.jsp) with the wrapper as parameter

                  - page1.jsp calls the include

                    - filter gets executed on page2.jsp - here if I output the javax.servlet.include attributes, they are set (which is good)

                      - filter doesn't create wrapper anymore, but uses the same

                      - filter calls again chain (page2.jsp) with the same original requests

                        - page2.jsp outputs the include attributes, which are set (which is good)

             

            something like this, I'll be back with details.

            • 3. Re: request include attributes missing in the included jsp
              ranjix Newbie

              In the end, the issue in my app is that I expect (unfortunately) that the requestwrapper.setAttribute is being called when the <jsp:include> gets executed. It looks like WebLogic and Websphere do it, while JBoss (Tomcat) doesn't. The servlet 2.5 specs doesn't really seem to force any specific behavior in this regards, so not sure what's the correct answer.