File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet" Watch "Servlet" New topic


Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Anybody can Explain URL Rewriting with one real time
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1868
Hi maheshwari,
Many a times we would like to invoke a servlet directly, rather than while submiting a form which represents date entered by a user. For example there may be three HTML links on a page. Clicking one of the three buttons would get me either of Record 1, Record 2, Record 3 from a database.
< a href=" <A HREF=" rel="nofollow"><Record" TARGET=_blank>><Record> 1
thus this is not a form but the data is passed with the hyperlink itself being id=1.

disadvantages of URLRewriting include
1) the URL is limited in size.
2) the URL can be seen and invoked by others from other pages .
3) the pages have to be dynamically generated
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
What you've described is not usually known as URL-rewriting; it's just using GET instead of POST to pass parameters to a servlet. URL-rewriting is a technique used with sessions.
The HTTP protocol used for transferring web pages is basically "stateless" - a request should generate the same response regardless of what other requests have been made. This can make it difficult to design "web applications" where the server response
needs to depend on what the user has already done.
The usual solution to this is "sessions". A session is a collection of data stored on the server and accessed using a specific key, known as a "session id". When a user starts a web application, a new session id is issued, and all information relating to that use of the web application is stored with that collection.
In order for the server to know which session a HTTP request belongs to, the browser must send back the appropriate session id. This can be done in three basic ways:
1. Cookies. This is the most popular method of session handling. If cookies are available in the browser all that is needed is for the web application to set a cookie and the browser will automatically send it back with every request.
2. Manual session handling. It is sometimes possible to make every page displayed by the web application a HTML form, with a hidden field containing the session id. This has the advantage of working with any web server, any browser and any scripting language, but it is difficult to get right, and doesn't suit all applications.
3. URL-rewriting. Every page displayed by the web application is processed before sending to the browser. The processing adds the session id to every URL it finds in the HTML. That way, whichever link or button the user clicks, it will stay with the same session.
The Servlet API has special support for URL-rewriting using the HttpServletResponse.encodeURL() method.
[This message has been edited by Frank Carver (edited August 16, 2000).]

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Servlet
It's not a secret anymore!