You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mon Cab <fu...@yahoo.com> on 2007/08/01 20:33:52 UTC

Forwarding based on URI's in Tomcat

I am trying to get tomcat to forward requests as follows

www.mysite.com/foo to direct to the foo action  
www.mysite.com/bar to direct to bar action ie. bar.do

Does anyone have any pointers on this?  Sorry for the newbie question. 


       
____________________________________________________________________________________
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
http://farechase.yahoo.com/

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Forwarding based on URI's in Tomcat

Posted by Mon Cab <fu...@yahoo.com>.
I would rather do this by configuring Tomcat, than doing it
programatically if posible.  


--- "Asensio, Rodrigo" <ro...@gilbarco.com> wrote:

> Are those 2 different webapps ?
> If yes, you have to be aware of session data, diff webapps do not
> share
> by default the session data.
> 
> But basically to do a client redirect you do this
> 
> Response.sendRedirect("otherURl")  >> this will change the url in the
> client browser
> 
> To do a server redirect you can do either
> <jsp:forward page="otherURL">
> 
> Or inside a servlet (or jsp)
> 
>
request.getContext().getRequestDispatcher("otherURL").forward(request,re
> sponse);
> 
> 
> regards
> 
> -----Original Message-----
> From: Mon Cab [mailto:futon33@yahoo.com] 
> Sent: Wednesday, August 01, 2007 2:34 PM
> To: Tomcat Usergroup
> Subject: Forwarding based on URI's in Tomcat
> 
> 
> I am trying to get tomcat to forward requests as follows
> 
> www.mysite.com/foo to direct to the foo action www.mysite.com/bar to
> direct to bar action ie. bar.do
> 
> Does anyone have any pointers on this?  Sorry for the newbie
> question. 
> 
> 
>        
>
________________________________________________________________________
> ____________
> Looking for a deal? Find great prices on flights and hotels with
> Yahoo!
> FareChase.
> http://farechase.yahoo.com/
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
> e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> 
> This message (including any attachments) contains confidential
> and/or proprietary information intended only for the addressee.
> Any unauthorized disclosure, copying, distribution or reliance on
> the contents of this information is strictly prohibited and may
> constitute a violation of law.  If you are not the intended
> recipient, please notify the sender immediately by responding to
> this e-mail, and delete the message from your system.  If you
> have any questions about this e-mail please notify the sender
> immediately.
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 



       
____________________________________________________________________________________
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 
http://mobile.yahoo.com/go?refer=1GNXIC

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Forwarding based on URI's in Tomcat

Posted by "Asensio, Rodrigo" <ro...@gilbarco.com>.
Are those 2 different webapps ?
If yes, you have to be aware of session data, diff webapps do not share
by default the session data.

But basically to do a client redirect you do this

Response.sendRedirect("otherURl")  >> this will change the url in the
client browser

To do a server redirect you can do either
<jsp:forward page="otherURL">

Or inside a servlet (or jsp)

request.getContext().getRequestDispatcher("otherURL").forward(request,re
sponse);


regards

-----Original Message-----
From: Mon Cab [mailto:futon33@yahoo.com] 
Sent: Wednesday, August 01, 2007 2:34 PM
To: Tomcat Usergroup
Subject: Forwarding based on URI's in Tomcat


I am trying to get tomcat to forward requests as follows

www.mysite.com/foo to direct to the foo action www.mysite.com/bar to
direct to bar action ie. bar.do

Does anyone have any pointers on this?  Sorry for the newbie question. 


       
________________________________________________________________________
____________
Looking for a deal? Find great prices on flights and hotels with Yahoo!
FareChase.
http://farechase.yahoo.com/

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org To unsubscribe,
e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org



This message (including any attachments) contains confidential 
and/or proprietary information intended only for the addressee.  
Any unauthorized disclosure, copying, distribution or reliance on 
the contents of this information is strictly prohibited and may 
constitute a violation of law.  If you are not the intended 
recipient, please notify the sender immediately by responding to 
this e-mail, and delete the message from your system.  If you 
have any questions about this e-mail please notify the sender 
immediately. 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Bill,

Bill Barker wrote:
> "Christopher Schultz" <ch...@christopherschultz.net> wrote in message 
>>       <servlet-name>action</servlet-name>
>>       <url-pattern>/mymodule/sexy*</url-pattern>
>>       <url-pattern>/mymodule/sexy</url-pattern>
>> 
>> That is, map both "/sexy*" and "/sexy" to the servlet.
> 
> 
> Nope, "/sexy*" is an exact-match pattern to a URL that is literally 
> "/myapp/sexy*".  The servlet-spec doesn't implement arbitrary regex 
> patterns, only the ones specified.  In this case you need to have the 
> url-pattern to be /sexy/* to get a prefix match.  And, yes, this will match 
> to a URL of "/myapp/sexy" (with an empty pathInfo).

I'm pretty sure that the trailing "/" is required in the pattern
"/sexy/*", so it would match "/sexy/" but not "/sexy". I don't think
that / counts as part of a wildcard expression.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGsdEX9CaO5/Lv0PARAudJAKCxJiF7GukKtxB+8W4hwmZ0jbaoKACfVDWO
BcXGvffve4h4rdU0GNiHgeY=
=c4y5
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Bill Barker <wb...@wilshire.com>.
"Christopher Schultz" <ch...@christopherschultz.net> wrote in message 
news:46B0FD35.2010009@christopherschultz.net...
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Mon,
>
> Mon Cab wrote:
>>       <url-pattern>/sexy*</url-pattern>
>
> I believe that the pattern "/sexy*" does not match when the * matches
> nothing. I think that * acts like + in a regular expression. You might 
> want:
>
>       <servlet-name>action</servlet-name>
>       <url-pattern>/mymodule/sexy*</url-pattern>
>       <url-pattern>/mymodule/sexy</url-pattern>
>
> That is, map both "/sexy*" and "/sexy" to the servlet.
>

Nope, "/sexy*" is an exact-match pattern to a URL that is literally 
"/myapp/sexy*".  The servlet-spec doesn't implement arbitrary regex 
patterns, only the ones specified.  In this case you need to have the 
url-pattern to be /sexy/* to get a prefix match.  And, yes, this will match 
to a URL of "/myapp/sexy" (with an empty pathInfo).

> - -chris
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGsP019CaO5/Lv0PARAmwEAJ9HU8lAnNcIR7RqbeQLvfTdE/4kIACdHp54
> lpCG2nsMLk2h3TITEGMNZmE=
> =xiSJ
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
> 




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Hassan Schroeder <ha...@gmail.com>.
On 8/1/07, Mon Cab <fu...@yahoo.com> wrote:

> and none of it seems to work.

Honestly, this sounds like a job for UrlRewriteFilter --
  <http://tuckey.org/urlrewrite/>

Worth a look, anyway :-)

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Mon Cab <fu...@yahoo.com>.
I tried 

 <servlet-name>action</servlet-name>
 <url-pattern>/mymodule/sexy*</url-pattern>
 <url-pattern>/mymodule/sexy</url-pattern>
<url-pattern>/sexy*</url-pattern>
 <url-pattern>/sexy</url-pattern>

and none of it seems to work. 



--- Christopher Schultz <ch...@christopherschultz.net> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Mon,
> 
> Mon Cab wrote:
> >       <url-pattern>/sexy*</url-pattern>
> 
> I believe that the pattern "/sexy*" does not match when the * matches
> nothing. I think that * acts like + in a regular expression. You
> might want:
> 
>        <servlet-name>action</servlet-name>
>        <url-pattern>/mymodule/sexy*</url-pattern>
>        <url-pattern>/mymodule/sexy</url-pattern>
> 
> That is, map both "/sexy*" and "/sexy" to the servlet.
> 
> - -chris
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.7 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFGsP019CaO5/Lv0PARAmwEAJ9HU8lAnNcIR7RqbeQLvfTdE/4kIACdHp54
> lpCG2nsMLk2h3TITEGMNZmE=
> =xiSJ
> -----END PGP SIGNATURE-----
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 



       
____________________________________________________________________________________
Be a better Globetrotter. Get better travel answers from someone who knows. Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=list&sid=396545469

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Mon,

Mon Cab wrote:
>       <url-pattern>/sexy*</url-pattern>

I believe that the pattern "/sexy*" does not match when the * matches
nothing. I think that * acts like + in a regular expression. You might want:

       <servlet-name>action</servlet-name>
       <url-pattern>/mymodule/sexy*</url-pattern>
       <url-pattern>/mymodule/sexy</url-pattern>

That is, map both "/sexy*" and "/sexy" to the servlet.

- -chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGsP019CaO5/Lv0PARAmwEAJ9HU8lAnNcIR7RqbeQLvfTdE/4kIACdHp54
lpCG2nsMLk2h3TITEGMNZmE=
=xiSJ
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by Mon Cab <fu...@yahoo.com>.
I tried the following 

 <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
   <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>/sexy*</url-pattern>
  </servlet-mapping>

but got a 404 message: 

The requested resource (/mymodule/sexy) is not available.

I also tried:

<servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>/mymodule/sexy*</url-pattern>
  </servlet-mapping>

but I got the same error. 




--- David Delbecq <de...@oma.be> wrote:

> In your web.xml, you can map /foo  and /bar to struts servlet.
> However,
> i think i remember the struts servlet does not like to be mapped at
> several location. (/foo, /bar and *.do)
> 
> You could also write your own servlet, that your map to /foo and /bar
> and which take th request url and does an internal forward to the
> same
> name with an additionnal .do
> 
> You could also map / to your struts servlet (instead of *.do) and
> have
> static content served using a servlet mapped to /static. But you will
> have problem with pure JSPs as you will need to manually map them.
> 
> 
> 
> Mon Cab a écrit :
> > I am trying to get tomcat to forward requests as follows
> >
> > www.mysite.com/foo to direct to the foo action  
> > www.mysite.com/bar to direct to bar action ie. bar.do
> >
> > Does anyone have any pointers on this?  Sorry for the newbie
> question. 
> >
> >
> >        
> >
>
____________________________________________________________________________________
> > Looking for a deal? Find great prices on flights and hotels with
> Yahoo! FareChase.
> > http://farechase.yahoo.com/
> >
> >
> ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >   
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 



       
____________________________________________________________________________________
Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online.
http://smallbusiness.yahoo.com/webhosting 

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Forwarding based on URI's in Tomcat

Posted by David Delbecq <de...@oma.be>.
In your web.xml, you can map /foo  and /bar to struts servlet. However,
i think i remember the struts servlet does not like to be mapped at
several location. (/foo, /bar and *.do)

You could also write your own servlet, that your map to /foo and /bar
and which take th request url and does an internal forward to the same
name with an additionnal .do

You could also map / to your struts servlet (instead of *.do) and have
static content served using a servlet mapped to /static. But you will
have problem with pure JSPs as you will need to manually map them.



Mon Cab a écrit :
> I am trying to get tomcat to forward requests as follows
>
> www.mysite.com/foo to direct to the foo action  
> www.mysite.com/bar to direct to bar action ie. bar.do
>
> Does anyone have any pointers on this?  Sorry for the newbie question. 
>
>
>        
> ____________________________________________________________________________________
> Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
> http://farechase.yahoo.com/
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org