• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Request Parameters

 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Richard Green
Ranch Hand
Posts: 536
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks lot, Bear and Richard.
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic