File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

referencing a variable in a jsp from a servlet

 
Annette L'Heureux
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1070
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving this to the JSP/Servlet forum where you will get a better response.
Bill
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Annette L'Heureux
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great! I didn't realize it would be that easy! (Or at least I'm hoping it will be!).
thanks!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic