This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Embed data in a url and pass it to a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Embed data in a url and pass it to a servlet" Watch "Embed data in a url and pass it to a servlet" New topic
Author

Embed data in a url and pass it to a servlet

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Hi i am currently stuck in a dilemma. I was thinking about an application in which users could add books randomly..
Now when the database is queried it displays all the books present with a hyperlink under the names of the books.When a user clicks on the hyperlink a separate jsp page is loaded with the details of the book.
What i wanted to do was embed the name of a book and its id in the hyperlink and when the servlet runs it extracts the data from the jsp. How could i do that. One way i think would be is to use a hidden input box .. any other recommendations ??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

The modern way to do it is with a RESTful URL.

For example: /contextpath/servletpath/books/213

Which would retrieve and display the information for the book with the id of 213.

It's also perfectly acceptable to pass the id as a request parameter in the query string, just not as new wave.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
Cant seem to find any information of restful url ? Could you please explain it a little?
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Representational State Transfer on Wikipedia


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Miku Ranjan
Ranch Hand

Joined: Oct 11, 2011
Posts: 98
Hi,
You can send data in url string itsel as follow:
yoururl?key=value&key2=value2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60794
    
  65

Miku Ranjan wrote:Hi,
You can send data in url string itsel as follow:
yoururl?key=value&key2=value2

Yeah, if you want to be "old school".
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Embed data in a url and pass it to a servlet
 
Similar Threads
Enable/Disable Hyperlink (Multiple Submits)
Passing parameters to the servlet
Communication session , servlet applet and back from applet servlet and session
Embedding icon image
logout problem