File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes From jsp to servlet to jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "From jsp to servlet to jsp?" Watch "From jsp to servlet to jsp?" New topic
Author

From jsp to servlet to jsp?

Jake Stevens
Greenhorn

Joined: Mar 28, 2009
Posts: 3
Hi All. I'm fairly new writing java so please forgive the errors.
I'm trying to create a wep site which displays a list of items (got that far). Then i want to be able to click on one of the items, I know it goes through a servlet at this point, to show more details about that item in particular . I know it has to do with sessions, passing a variable as a parameter. But not to sure how. I can make it happen if I use a form on the first page, but don't want to have to type anything in, just click on that specific item. Any help? Many thanks in advance.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
So you want a link which points to a servlet which returns the desired result based on the request parameter? Then just do that so?

1) Place a HTML <a> element in the JSP representing a link and let its href point to a servlet with a request parameter.
2) Create a servlet which gets the request parameter, returns the desired result based on it and forwards to a JSP file.
3) Create a JSP which displays the result.

This has not much to do with sessions.
Jake Stevens
Greenhorn

Joined: Mar 28, 2009
Posts: 3
Thank you for reponding to my problem. I tried to do what you suggested and I can link to the second jsp, I'm just not too sure how to word, or where to place the request parameter so that details of only that one specific item will be displayed once it goes to the servlet. Would appreciate any help.
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
In the forwarded JSP you can access the initial request parameters by ${param.name} where the 'name' part represents the parameter name. Alternatively (or additionally), in the servlet you can place new values and/or javabeans in the request scope by HttpServletRequest#setAttribute() which on its turn is accessible the usual EL way by ${attributename} or ${beanname.propertyname}.
Jake Stevens
Greenhorn

Joined: Mar 28, 2009
Posts: 3
Last chance for me I think. I just don't understand it, so if you don't want to respond that's ok. Maybe thinking about too many thing all at once in this netbeans.
Posting some of the code to see if you can see what I'm missing.

The viewjsp

and the servlet

Like I said, if it's too much trouble please don't bother yourself and many thanks for trying anyway javascript:emoticon('');
Nick Potter
Ranch Hand

Joined: May 07, 2008
Posts: 126
Here's a basic example:

In first jsp you have something like this: where Controller is the url-mapping of your servlet and parameter is the request param you want to send to the servlet with the value=paramValue;
In servlet you've got:

you now have 2 parameters in the request: parameter and parameter2. You access the in the newjsp.jsp liek this:

You shouldn't do sql queries, etc in the servlet, but in a separate java class.


Maybe it's better if you read carefully some servlet & jsp tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: From jsp to servlet to jsp?