This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Servlets and the fly likes Opening a page with details about an item (servlet) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Opening a page with details about an item (servlet)" Watch "Opening a page with details about an item (servlet)" New topic
Author

Opening a page with details about an item (servlet)

Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
Hi!

I am trying to create a web application in java. I am using servlets. I have come to the stage where the user enters a search query and receives a list of items which match his/her query. When the user gets a list of items which match, how can I make it possible for the user to click on an item and it opens a "show" servlet page and this takes the information regarding the item and displays them in this page?


I have tried the below code but this occurs before the list even appears:



I don't know whats wrong.

Thanks for any replies
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
First of all this is a very bad practice. You should be using servlets only as controllers, and the view should be a JSP, or even a static HTML page with some AJAX. But either way, to get the result you need to display the results to the user in some table [which you are not doing], and the javascript invocation you are doing is wrong.

onClick='openItemDetails(itemToGet.getId())' should be changed to onClick='openItemDetails(<%=itemToGet.getId()%>)'

since itemToGet.getId() is a java object and not a javascript object.

Dawn.
Charlie Jones
Greenhorn

Joined: Apr 06, 2009
Posts: 14
do you know any good tutorials how to use servlets as controllers?

I'm sorry for my question - I'm still learning how to use everything
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
head first servlets and JSPs are my personal favourite....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

Please read this article.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Opening a page with details about an item (servlet)
 
Similar Threads
Servlet API 2.2
RequestDispatcher Include
servlet exception error in my code(urgent)
retrieve value at servlet from javascript.
Deleting multiple records using jQuery-ajax at a time.