File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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.
original urls
Ben Souther

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 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

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: 105


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

Website: Learn Java by Examples
It is sorta covered in the JavaRanch Style Guide.
subject: url formating in web apps
It's not a secret anymore!