This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
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
Joined: Jan 07, 1999
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.
Joined: Dec 07, 2000
Great! I didn't realize it would be that easy! (Or at least I'm hoping it will be!). thanks!