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

Request Parameters

Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
Usually, in a Servlet we write, for example, http://test.com/cust.do?no=1, to get details reg. say, customer no. 1. But recently I came across a URL written as http://localhost:8080/rest/customer/1.txt, which works perfectly well and the servlet returns the first record. My doubt is how the getParameter will return the value.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Sunder Ganapathy:
My doubt is how the getParameter will return the value.

It won't. There are no parameters on the request.

The servlet handling this URL will have to parse the extra info on the URL to obtain the "1" value.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
your webserver (Apache / IIS) can be setup to perform a URL rewrite from http://localhost:8080/rest/customer/1.txt to http://localhost:8080/rest/cust.do?no=1 (The rewritten url is not shown to the user)


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Originally posted by Richard Green:
your webserver (Apache / IIS) can be setup to perform a URL rewrite

Why bother? Besides, the use of Apache or other static web server to front an app server is seriously on the wane.

This can be dealt with directly in the servlet or front controller.
[ November 07, 2007: Message edited by: Bear Bibeault ]
Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
Thanks lot, Bear and Richard.
Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
How to do the parsing, because the servlet gives 404 error, when 1.txt is added to the URL. Really getting stumped, after having worked with regular URL handling with getParameter etc.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Sounds like you don't have the mapping set up correctly. How are you mapping the servlet?

By the way, if you want to see an example, check out FrontMan, my implementation of a Front Controller. See link in my sig.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Request Parameters