Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Apache Tomcat »

Re: Tomcat 5.5 redirect vs. forward behavior with welcome-file-list

Stefan

2007-02-12

Replies:

Todd Gamber schrieb:
> In Tomcat 4.1, a request to a directory containing a welcome-file would
> *redirect* the user to a URL with any applicable welcome-file's name
> appended. In Tomcat 5.5, the request is instead *forwarded* to the welcome
> file.
>
> Is there a way to make Tomcat 5.5 act like Tomcat 4.1 in this respect?
>
> For example:
> I have a web.xml which contains:
> <welcome-file-list>
>  <welcome-file>index.jsp</welcome-file>
> </welcome-file-list>
>
> In Tomcat 4.1, a request to http://www.mysite.com/directory/ makes the
> browser refresh with a URL of http://www.mysite.com/directory/index.jsp
>
> In Tomcat 5.5, the same request leaves the browser with the same URL
> http://www.mysite.com/directory/.
>
>
> BACKGROUND:
> I'm using Tomcat 5.5.17 on Windows XP, and unfortunately, my application is
> dependent on the redirect behavior of Tomcat 4.1 because my JSPs use
> HttpServletRequest.getRequestURI() to find the name of the JSPs themselves.
> The JSPs pull their content from the database based on the URL being
> requested. So, if the browser's URL bar reads
> http://www.mysite.com/directory/index.jsp, the 'index.jsp' queries the DB
> for content based on the path '/directory/index.jsp'. Conversely, if the
> browser's URL bar reads http://www.mysite.com/directory/, the same JSP looks
> for database rows using the path '/directory/'. Naturally, because Tomcat
> 5.5 acts differently, similar requests receive different content.
>
> I realize that populating content based on what's in the URL bar is not the
> best design, but I can't seem to find another way to definitively get the
> name of the actual JSP being requested. If anybody knows of a method similar
> to getRequestURI(), but which knows the name of the JSP being requested, it
> would help tremendously.
>
> Thanks,
> Todd
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@(protected)
> To unsubscribe, e-mail: users-unsubscribe@(protected)
> For additional commands, e-mail: users-help@(protected)
>
>
>  
By the way Todd. Use HttpServletRequest.getServletPath() instead of
HttpServletRequest.getRequestURI(). This will report the forwarded path
without the context path information.

Regards
Stefan

--
Stefan



---------------------------------------------------------------------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.