File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes referencing a variable in a jsp from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "referencing a variable in a jsp from a servlet" Watch "referencing a variable in a jsp from a servlet" New topic
Author

referencing a variable in a jsp from a servlet

Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
How do you reference a variable in a servlet that you've created in a jsp?
I can't figure out how to link the jsp and the servlet together, because my servlet accesses my database depending on the selection that the user makes, with is recorded in a jsp. Any ideas?
Annette
bill bozeman
Ranch Hand

Joined: Jun 30, 2000
Posts: 1070
I am moving this to the JSP/Servlet forum where you will get a better response.
Bill
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
The answer depends how the JSP calls the servlet. If the JSP calls the servlet by submitting a form, then you might as well pass the value in a hidden form field. If the value is known at the time the JSP is created, you can put it in the session information which wil be accessible from bothe the JSP and the servlet.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Thanks! I've been looking into how to display a textbox on my web page and it looks like a pretty simple way is to use a form. So if I use a "submit form" button, you're saying that I can't pass the values to the service method? I thought that using a hidden form field meant that you couldn't see the value. Then the user would not be able to type the value in!
I guess the real question in all of this is, can I use a "submit form" button and pass the values to a method? And if so, how do you tell it the method you want to pass those values to?
Annette
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
OK. I thought you were looking for a way to pass a value from the JSP code which generates a page straight to the servlet which processes the user's input. If you just want to allow the user to enter some stuff which is passed to a servlet to be processed, then by all means build a form and set the submit button to POST it to ths servlet.
Annette L'Heureux
Ranch Hand

Joined: Dec 07, 2000
Posts: 135
Great! I didn't realize it would be that easy! (Or at least I'm hoping it will be!).
thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: referencing a variable in a jsp from a servlet
 
Similar Threads
using libtags
passing objects from servlet to jsp
inserting information in DB from jsp
session variable
regarding anchor tag to servlet