aspose file tools*
The moose likes Servlets and the fly likes url formating in web apps Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "url formating in web apps" Watch "url formating in web apps" New topic
Author

url formating in web apps

azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
I would like the URLs in my apps in a certain format.
Eg:
original urls
http://www.domain.com/list.jsp?country=uk&city=london&category=entertainment
required
http://www.domain.com/uk/london/entertainment/list.jsp
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

OK, is there a question there?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Atul Sawant
Ranch Hand

Joined: Jul 06, 2006
Posts: 304
The two urls you have given are quite different.
the first one uses the uk, london etc...as parameters whereas the the second url used them as an address where the the jsp page "list" is stored.

If you do not want to shows the parameters in the urls you can use "post" method instead of default "get" method.
[ March 25, 2007: Message edited by: Atul Savant ]

Mission SCWCD. Mission SCJP Complete: SCJP 1.4 - 91%
azhar bharat
Ranch Hand

Joined: Jul 17, 2006
Posts: 87
Sorry. but i dint frame my question right, and hence the confusion.
My requirement is simple.Let me explain with an example.

Consider a property classifieds site. A user who wants to view the properties in london currently browsing through the site clicks on the corresponding link (first for country and then for city). The page url looks something like this : http://mydomain/list.jsp?country=uk&city=london.

Now what i intend to do. I want the visitor to view the same listing as above by typing the city and country in the url. i.e. http://mydomain/uk/london/

i hope i am clear this time.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Two things you might want to read up on.

1.) The 'servlet-mapping' entries in the deployment descriptor.
The best place to go for information on these is the servlet spec.

2.) The 'front controller' or command pattern.
There are several conversations going on regarding this front controllers in this forum right now.


In a nutshell, you can create a servlet mapping that traps any requests with a given pattern (Struts filters on the ".do" extension) and routes the request to your front controller. From there, your front controller can analyze the URL (using the HttpServletRequest object) and forward the request to whatever command object you like.
Wayan Saryada
Ranch Hand

Joined: Feb 05, 2004
Posts: 104

Hi,

What about using something like URL rewriting library? I think it can help you to create a friendly url for user to access your website. Try something like http://tuckey.org/urlrewrite/.


Website: Learn Java by Examples
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: url formating in web apps
 
Similar Threads
Buying Electronics in UK
need to redirect based on URL
http and www
How to book a slot for the SCJP exam
Practical WebObjects Questions