You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Neil Aggarwal <ne...@JAMMConsulting.com> on 2003/08/27 02:44:46 UTC

Request dispatcher fails on encoded url when used in post (Bug?)

Hello:

I am getting a failure in my code when using a request dispatcher
to forward the request to an encoded url from a post operation.

To see it in action, do the following:
1. Turn off cookies on your browser
2. Visit http://dev.jammconsulting.com/gen?_template=/index.jsp
3. Hit the Test button.

You will get this error:

HTTP Status 404 - /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
------------------------------------------------------------------------
--------
type Status report
message /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
description The requested resource
(/gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5) is not available.
------------------------------------------------------------------------
--------
Apache Tomcat/4.1.27

Now, turn on cookies and try it again.  You will get a page that states:
This is compose.jsp 
Session id is BFBC13C89DD4B3F5A98EF8E53F0D6A45 

I thought that Tomcat is supposed to act the same with cookies on or off

when I use encodeURL on all of my urls.


Here is the code behind this sample:

In httpd.conf, ask apache to map all urls that begin with /gen into
tomcat:
  <LocationMatch /gen>
    JkUriSet worker ajp13:localhost:8009
  </LocationMatch>

In tomcat server.xml, I told tomcat that the root context uses
my app:
<Context path="" docBase="email" debug="0"/>

In my app's web.xml, told it to map all request for /gen to
my test servlet:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <servlet>
        <servlet-name>sls</servlet-name>
        <servlet-class>
            servlet.TestServlet
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>sls</servlet-name>
        <url-pattern>/gen/*</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>50</session-timeout>
    </session-config>
    
</web-app>

Here is my test servlet, which forwards all requests to the appropriate
template:
package servlet;

import java.io.*;
import java.net.*;

import javax.servlet.*;
import javax.servlet.http.*;

public class TestServlet extends HttpServlet {
  private void process(HttpServletRequest request, HttpServletResponse
response)
  throws ServletException, IOException {
 
getServletContext().getRequestDispatcher(request.getParameter("_template
")).forward(request, response);
  }
  
  protected void doGet(HttpServletRequest request, HttpServletResponse
response)
  throws ServletException, IOException {
    process(request,response);
  }
  
  protected void doPost(HttpServletRequest request, HttpServletResponse
response)
  throws ServletException, IOException {
    process(request,response);
  }
}

Here is the index.jsp template, which posts to the massCompose template:
<P>
Session id is <%= session.getId() %>
<P>

<form name=groupList method="post" action="<%=
response.encodeUrl("/gen") %>">
  <input type=hidden name="_template" value="/massCompose.jsp">
  <input type="submit" value="test">
</form>

Here is the massCompose template which forwards to the compose template:
<% 
  RequestDispatcher rdispatch = 
request.getRequestDispatcher(response.encodeURL("/gen?_template=/compose
.jsp&type=normal"));
  rdispatch.forward(request, response);
%>

Here is the compose template which just displays a message:
<HTML>

  <BODY>
    This is compose.jsp
    <P>
    Session id is <%= session.getId() %>
    <P>
  </BODY>

</HTML>

Any ideas why this is occurring?

Thanks,
	Neil

--
Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
FREE! Valuable info on how your business can reduce operating costs by 
17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com


Re: Request dispatcher fails on encoded url when used in post (Bug?)

Posted by Bill Barker <wb...@wilshire.com>.
See http://nagoya.apache.org/bugzilla/show_bug.cgi?id=22734.  You can also
search bugzilla, since this one has come up several times (this is just the
latest incarnation :).

"Neil Aggarwal" <ne...@JAMMConsulting.com> wrote in message
news:000101c36c34$6b2d83b0$6501a8c0@dell5100...
> Hello:
>
> I am getting a failure in my code when using a request dispatcher
> to forward the request to an encoded url from a post operation.
>
> To see it in action, do the following:
> 1. Turn off cookies on your browser
> 2. Visit http://dev.jammconsulting.com/gen?_template=/index.jsp
> 3. Hit the Test button.
>
> You will get this error:
>
> HTTP Status 404 - /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> ------------------------------------------------------------------------
> --------
> type Status report
> message /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> description The requested resource
> (/gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5) is not available.
> ------------------------------------------------------------------------
> --------
> Apache Tomcat/4.1.27
>
> Now, turn on cookies and try it again.  You will get a page that states:
> This is compose.jsp
> Session id is BFBC13C89DD4B3F5A98EF8E53F0D6A45
>
> I thought that Tomcat is supposed to act the same with cookies on or off
>
> when I use encodeURL on all of my urls.
>
>
> Here is the code behind this sample:
>
> In httpd.conf, ask apache to map all urls that begin with /gen into
> tomcat:
>   <LocationMatch /gen>
>     JkUriSet worker ajp13:localhost:8009
>   </LocationMatch>
>
> In tomcat server.xml, I told tomcat that the root context uses
> my app:
> <Context path="" docBase="email" debug="0"/>
>
> In my app's web.xml, told it to map all request for /gen to
> my test servlet:
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
>
>     <servlet>
>         <servlet-name>sls</servlet-name>
>         <servlet-class>
>             servlet.TestServlet
>         </servlet-class>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>sls</servlet-name>
>         <url-pattern>/gen/*</url-pattern>
>     </servlet-mapping>
>
>     <session-config>
>         <session-timeout>50</session-timeout>
>     </session-config>
>
> </web-app>
>
> Here is my test servlet, which forwards all requests to the appropriate
> template:
> package servlet;
>
> import java.io.*;
> import java.net.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class TestServlet extends HttpServlet {
>   private void process(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>
> getServletContext().getRequestDispatcher(request.getParameter("_template
> ")).forward(request, response);
>   }
>
>   protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>     process(request,response);
>   }
>
>   protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>     process(request,response);
>   }
> }
>
> Here is the index.jsp template, which posts to the massCompose template:
> <P>
> Session id is <%= session.getId() %>
> <P>
>
> <form name=groupList method="post" action="<%=
> response.encodeUrl("/gen") %>">
>   <input type=hidden name="_template" value="/massCompose.jsp">
>   <input type="submit" value="test">
> </form>
>
> Here is the massCompose template which forwards to the compose template:
> <%
>   RequestDispatcher rdispatch =
> request.getRequestDispatcher(response.encodeURL("/gen?_template=/compose
> .jsp&type=normal"));
>   rdispatch.forward(request, response);
> %>
>
> Here is the compose template which just displays a message:
> <HTML>
>
>   <BODY>
>     This is compose.jsp
>     <P>
>     Session id is <%= session.getId() %>
>     <P>
>   </BODY>
>
> </HTML>
>
> Any ideas why this is occurring?
>
> Thanks,
> Neil
>
> --
> Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by
> 17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com




RE: Request dispatcher fails on encoded url when used in post (Bug?)

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
Filip:

There is no space in the url, it is an underscore.

As far as the last slash, why would it work correctly with cookies
on and not with cookies off?  

It should work the same with and without cookies. If it did not work 
in both cases, that would make sense to me.

Thanks,	
	Neil

--
Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
FREE! Valuable info on how your business can reduce operating costs by 
17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com

> -----Original Message-----
> From: Filip Hanik [mailto:mail@filip.net] 
> Sent: Tuesday, August 26, 2003 8:12 PM
> To: Tomcat Users List
> Subject: RE: Request dispatcher fails on encoded url when 
> used in post (Bug?)
> 
> 
> that is a funky url, it has a space in it, and the last "/" should be
> encoded
> 
> Filip
> 
> > -----Original Message-----
> > From: Neil Aggarwal [mailto:neil@JAMMConsulting.com]
> > Sent: Tuesday, August 26, 2003 5:45 PM
> > To: 'Tomcat-User'
> > Cc: Jeff Patterson
> > Subject: Request dispatcher fails on encoded url when used in post
> > (Bug?)
> >
> >
> > Hello:
> >
> > I am getting a failure in my code when using a request dispatcher
> > to forward the request to an encoded url from a post operation.
> >
> > To see it in action, do the following:
> > 1. Turn off cookies on your browser
> > 2. Visit http://dev.jammconsulting.com/gen?_template=/index.jsp
> > 3. Hit the Test button.
> >
> > You will get this error:
> >
> > HTTP Status 404 - /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> > 
> --------------------------------------------------------------
> ----------
> > --------
> > type Status report
> > message /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> > description The requested resource
> > (/gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5) is not available.
> > 
> --------------------------------------------------------------
> ----------
> > --------
> > Apache Tomcat/4.1.27
> >
> > Now, turn on cookies and try it again.  You will get a page 
> that states:
> > This is compose.jsp
> > Session id is BFBC13C89DD4B3F5A98EF8E53F0D6A45
> >
> > I thought that Tomcat is supposed to act the same with 
> cookies on or off
> >
> > when I use encodeURL on all of my urls.
> >
> >
> > Here is the code behind this sample:
> >
> > In httpd.conf, ask apache to map all urls that begin with /gen into
> > tomcat:
> >   <LocationMatch /gen>
> >     JkUriSet worker ajp13:localhost:8009
> >   </LocationMatch>
> >
> > In tomcat server.xml, I told tomcat that the root context uses
> > my app:
> > <Context path="" docBase="email" debug="0"/>
> >
> > In my app's web.xml, told it to map all request for /gen to
> > my test servlet:
> > <?xml version="1.0" encoding="ISO-8859-1"?>
> >
> > <!DOCTYPE web-app
> >     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
> >     "http://java.sun.com/dtd/web-app_2_3.dtd">
> >
> > <web-app>
> >
> >     <servlet>
> >         <servlet-name>sls</servlet-name>
> >         <servlet-class>
> >             servlet.TestServlet
> >         </servlet-class>
> >     </servlet>
> >
> >     <servlet-mapping>
> >         <servlet-name>sls</servlet-name>
> >         <url-pattern>/gen/*</url-pattern>
> >     </servlet-mapping>
> >
> >     <session-config>
> >         <session-timeout>50</session-timeout>
> >     </session-config>
> >
> > </web-app>
> >
> > Here is my test servlet, which forwards all requests to the 
> appropriate
> > template:
> > package servlet;
> >
> > import java.io.*;
> > import java.net.*;
> >
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> >
> > public class TestServlet extends HttpServlet {
> >   private void process(HttpServletRequest request, 
> HttpServletResponse
> > response)
> >   throws ServletException, IOException {
> >
> > 
> getServletContext().getRequestDispatcher(request.getParameter(
> "_template
> > ")).forward(request, response);
> >   }
> >
> >   protected void doGet(HttpServletRequest request, 
> HttpServletResponse
> > response)
> >   throws ServletException, IOException {
> >     process(request,response);
> >   }
> >
> >   protected void doPost(HttpServletRequest request, 
> HttpServletResponse
> > response)
> >   throws ServletException, IOException {
> >     process(request,response);
> >   }
> > }
> >
> > Here is the index.jsp template, which posts to the 
> massCompose template:
> > <P>
> > Session id is <%= session.getId() %>
> > <P>
> >
> > <form name=groupList method="post" action="<%=
> > response.encodeUrl("/gen") %>">
> >   <input type=hidden name="_template" value="/massCompose.jsp">
> >   <input type="submit" value="test">
> > </form>
> >
> > Here is the massCompose template which forwards to the 
> compose template:
> > <%
> >   RequestDispatcher rdispatch =
> > 
> request.getRequestDispatcher(response.encodeURL("/gen?_templat
> e=/compose
> > .jsp&type=normal"));
> >   rdispatch.forward(request, response);
> > %>
> >
> > Here is the compose template which just displays a message:
> > <HTML>
> >
> >   <BODY>
> >     This is compose.jsp
> >     <P>
> >     Session id is <%= session.getId() %>
> >     <P>
> >   </BODY>
> >
> > </HTML>
> >
> > Any ideas why this is occurring?
> >
> > Thanks,
> > 	Neil
> >
> > --
> > Neil Aggarwal, JAMM Consulting, (972)612-6056, 
www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by
> 17% or more in 6 months or less! =>
http://newsletter.JAMMConsulting.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


RE: Request dispatcher fails on encoded url when used in post (Bug?)

Posted by Filip Hanik <ma...@filip.net>.
that is a funky url, it has a space in it, and the last "/" should be
encoded

Filip

> -----Original Message-----
> From: Neil Aggarwal [mailto:neil@JAMMConsulting.com]
> Sent: Tuesday, August 26, 2003 5:45 PM
> To: 'Tomcat-User'
> Cc: Jeff Patterson
> Subject: Request dispatcher fails on encoded url when used in post
> (Bug?)
>
>
> Hello:
>
> I am getting a failure in my code when using a request dispatcher
> to forward the request to an encoded url from a post operation.
>
> To see it in action, do the following:
> 1. Turn off cookies on your browser
> 2. Visit http://dev.jammconsulting.com/gen?_template=/index.jsp
> 3. Hit the Test button.
>
> You will get this error:
>
> HTTP Status 404 - /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> ------------------------------------------------------------------------
> --------
> type Status report
> message /gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5
> description The requested resource
> (/gen;jsessionid=BF99242CF6F9E32C44D50EACE5576AD5) is not available.
> ------------------------------------------------------------------------
> --------
> Apache Tomcat/4.1.27
>
> Now, turn on cookies and try it again.  You will get a page that states:
> This is compose.jsp
> Session id is BFBC13C89DD4B3F5A98EF8E53F0D6A45
>
> I thought that Tomcat is supposed to act the same with cookies on or off
>
> when I use encodeURL on all of my urls.
>
>
> Here is the code behind this sample:
>
> In httpd.conf, ask apache to map all urls that begin with /gen into
> tomcat:
>   <LocationMatch /gen>
>     JkUriSet worker ajp13:localhost:8009
>   </LocationMatch>
>
> In tomcat server.xml, I told tomcat that the root context uses
> my app:
> <Context path="" docBase="email" debug="0"/>
>
> In my app's web.xml, told it to map all request for /gen to
> my test servlet:
> <?xml version="1.0" encoding="ISO-8859-1"?>
>
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/dtd/web-app_2_3.dtd">
>
> <web-app>
>
>     <servlet>
>         <servlet-name>sls</servlet-name>
>         <servlet-class>
>             servlet.TestServlet
>         </servlet-class>
>     </servlet>
>
>     <servlet-mapping>
>         <servlet-name>sls</servlet-name>
>         <url-pattern>/gen/*</url-pattern>
>     </servlet-mapping>
>
>     <session-config>
>         <session-timeout>50</session-timeout>
>     </session-config>
>
> </web-app>
>
> Here is my test servlet, which forwards all requests to the appropriate
> template:
> package servlet;
>
> import java.io.*;
> import java.net.*;
>
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class TestServlet extends HttpServlet {
>   private void process(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>
> getServletContext().getRequestDispatcher(request.getParameter("_template
> ")).forward(request, response);
>   }
>
>   protected void doGet(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>     process(request,response);
>   }
>
>   protected void doPost(HttpServletRequest request, HttpServletResponse
> response)
>   throws ServletException, IOException {
>     process(request,response);
>   }
> }
>
> Here is the index.jsp template, which posts to the massCompose template:
> <P>
> Session id is <%= session.getId() %>
> <P>
>
> <form name=groupList method="post" action="<%=
> response.encodeUrl("/gen") %>">
>   <input type=hidden name="_template" value="/massCompose.jsp">
>   <input type="submit" value="test">
> </form>
>
> Here is the massCompose template which forwards to the compose template:
> <%
>   RequestDispatcher rdispatch =
> request.getRequestDispatcher(response.encodeURL("/gen?_template=/compose
> .jsp&type=normal"));
>   rdispatch.forward(request, response);
> %>
>
> Here is the compose template which just displays a message:
> <HTML>
>
>   <BODY>
>     This is compose.jsp
>     <P>
>     Session id is <%= session.getId() %>
>     <P>
>   </BODY>
>
> </HTML>
>
> Any ideas why this is occurring?
>
> Thanks,
> 	Neil
>
> --
> Neil Aggarwal, JAMM Consulting, (972)612-6056, www.JAMMConsulting.com
> FREE! Valuable info on how your business can reduce operating costs by
> 17% or more in 6 months or less! => http://newsletter.JAMMConsulting.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>
>