tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Görling <stefan.gorl...@pricerunner.com>
Subject Re: Configuring a Default Servlet
Date Mon, 09 Feb 2004 12:53:01 GMT
Dear Tim and others,

Thank you for the reference. And now for the little twist which I forgot 
to mention:
Before we introduced the default servlet we had urls with normal .jsp:s. 
We want to run those through the custom dispatcher as well in order to 
redirect to the proper url

For example:
A request to: /Foo.jsp -> Permanent redirect to /foo/bar
A request to: /foo/bar --> Internal forward to www/Foo.jsp
A request to /Bar.jsp -->Internal forward to www/Bar.jsp

The problem is to say that all requests, including .jsp-files in the 
root should be handled by the Servlet, but _not_ .jsp-files residing in 
/www/

The following won't work: (neither with /www nor with /www/*)
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>/www*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>custom</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

As the getRequestDispatcher("/www/Foo.jsp").forward(request,response), 
creates a loop.

So:

Is it possible to:
a) configure web.xml in a proper way
b) get a JSP-dispatcher, like 
getJSPRequestDispatcher("/www/Foo.jsp").forward(request,response) 
(tomcat specific typecasting is ok).
c)  Rewrite the incoming RequestURI in a proper way?
I've written code for :
1. in apache using mod_rewrite to change all url:s so that they begin 
with /custom/foo/bar,
2. In the Servlet, wrap the request by extending the  
HttpServletRequestWrapper and overriding getRequestURI() so that  
/custom is removed.

This however gave a problem when trying to do a response.redirect to a 
relative URL, as tomcat used an internal representation of the Request 
object to retrieve the path information when converting the relative 
path to an aboslute one, hence giving back a /custom/foo/bar url. I can 
wrap the HttpServletResponse too to fix the redirect object, but I have 
no idea when the same problem will appear somewhere else.

Best Regards,

Stefan Görling

> The defualt servlet is mapped by the following:
>
> SRV.11.2 Specification of Mappings
> "A string containing only the ’/’ character indicates the "default" 
> servlet of the application. In this case the servlet path is the 
> request URI minus the context path and the path info is null."
>
> So you really want:
>   <url-pattern>/</url-pattern>
>
> Also that same section states the /* has higher precendence than 
> *.extension
>
> -Tim
>
> Stefan Görling wrote:
>
>> Hi,
>>
>> I want to have all incomming request forwarded to a default servlet. 
>> Depending on the URL the request is forwarded to a JSP-page (too 
>> dynamic to use apache mod_rewrite).
>>
>> The problem is that if I define the servlet as:
>>    <servlet-mapping>
>>        <servlet-name>custom</servlet-name>
>>        <url-pattern>/*</url-pattern>
>>    </servlet-mapping>
>>
>> It will work, but when I do 
>> getDispatcher("MyPage.jsp").forward(request,response), it will 
>> forward to the servlet in a recursive way.
>>
>> Is there any way to get a hold of a JSP-dispatcher when forwarding a 
>> request in order to do this?
>>
>
>
> ---------------------------------------------------------------------
> 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


Mime
View raw message