Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URL Rewriting in browser

 
Sohil Shah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is a web application hosted in tomcat.
It can be accessed through -
http://localhost:8080/MyApplicationContext

Now if I want to Access ant further java action, I access those through an ActionServlet which is written.

So the URL looks like

http://localhost:8080/MyApplicationContext/ActionServlet?MY_ACTION=DO_SOMETHING

This is how the current application works.
I now just want to rewrite the URL.

I will be given an extra word at runtime..e.g EXTRA_WORD

so if somebody tries to access the application using URL
http://localhost:8080/MyApplicationContext/EXTRA_WORD

Then that person should be able to access the same application.

Also, This EXTRA_WORD should remain in the URL throughout the application.

So any access to further actions should look like -

http://localhost:8080/MyApplicationContext/EXTRA_WORD/ActionServlet?MY_ACTION=DO_SOMETHING

Thanks,
Sohil
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you familiar with javax.servlet.Filter? Read on about them. This is a suitable Fitler task.
 
Sohil Shah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bauke,

Thanks for the reply.
I am using the filters only.
But can you please elaborate on what should I write in filters?

Actually, the thing is - I have created my application already. And it's working fine. The only thing I need to change is the URL the user sees. I just want to add an extra word in the URL.

Sohil.
 
Sohil Shah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bauke Scholtz:
Are you familiar with javax.servlet.Filter? Read on about them. This is a suitable Fitler task.


Hi Bauke,

Thanks for the reply.
I am using the filters only.
But can you please elaborate on what should I write in filters?

Actually, the thing is - I have created my application already. And it's working fine. The only thing I need to change is the URL the user sees. I just want to add an extra word in the URL.

Sohil.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sohil,

then, i think no need to go for filter. suppose you servlet mapping is /ACTION-SERVLET then change it to /EXTRA_WORDS/ACTION-SERVLET in web.xml
and then try. let see it helps you or not
 
Sohil Shah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by seetharaman venkatasamy:
Hi sohil,

then, i think no need to go for filter. suppose you servlet mapping is /ACTION-SERVLET then change it to /EXTRA_WORDS/ACTION-SERVLET in web.xml
and then try. let see it helps you or not


Hi Seetharaman,

The thing is that EXTRA_WORD is decided at runtime. I have list of those allowed wo rds on an XML file.
So it can be
/EXTRA_WORD1/ACTION-SERVLET or
/EXTRA_WORD2/ACTION-SERVLET etc.

Also if I change the servlet mapping , I don't think will work for me. Because I will need to change all the URLs and href in my application which simply works for /ACTION-SERVLET mapping.
 
Uli Hofstoetter
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you should rethink your design wether the EXTRA_WORD should rather be a request parameter than a part of the URI.
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just implement the filter on the generic url pattern and let it read the same configuration file how to forward the 'pretty URL' to a 'real url'. If there is no such mapping then just let it continue the request transparently.
 
Sohil Shah
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bauke Scholtz:
Just implement the filter on the generic url pattern and let it read the same configuration file how to forward the 'pretty URL' to a 'real url'. If there is no such mapping then just let it continue the request transparently.


Hi Bauke,

The thing is that..The application is already been created and it's up and it works fine without that EXTRA_WORD thing. i.e all JSPs and JS file contains all form Actions, hrefs, and ajax call in the form of ActionServlet?My_Action=Somthing..
So if I now want to insert this EXTRA_WORD, i'll have to change all these JSPs and JS files.

Let me put the problem in more simpler way.
we have an application .. it's hosted on ..say..
www.application.com
their users are say CUST1 and CUST2 and many more...
Previously, the customer were given the generic URL that is..www.application.com

now we want to give them more personalized URL like www.application.com/CUST1
Also we'll show some CSS effects on the bases the customer specific URL(like their logo or something like that)

Appreciate your help.

Thanks,
Sohil
 
raj malhotra
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sohil:
will be given an extra word at runtime..e.g EXTRA_WORD


You know that whatever action you are sending in request ,the web container will try to match it in web.xml to find a suitable match.
The point is, you should understand that web container is basically trying to do pattern matching.you have specified the Url-pattern for your servlet in the web.xml .

BUT you are trying to do the exact match.
There are three ways to give url pattern in the web.xml
1.Exact match
2.Directory match
3.Extension match

you should go with Directory match rather than exact match as your request action will change partially at runtime.
[ December 23, 2008: Message edited by: raj malhotra ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic