Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Urgent "SERVLET PROBLEM"  RSS feed

 
Kinga Cserveny
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI!
Can anyone tell me what are the different ways of passing variables to a SERVELT?
I have just started learning about them and find that there is just too much to lear....
Thanks for your help
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not exactly sure what you mean. But, to access variables passed in from your JSP/HTML page use getParameter and getParameterValues methods.
I will assume youi have a servelet/JSP book, if you don't, try getting one. The ones I use are, Core servlets & JSP by Marty Hall, and Jason Hunter's Java Servlet Programing.

Bosun
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try a different interpretation.

The two ways a servlet can be 'passed' variables is by POSTing them to the servlet, or GETing them. I've always thought the word GET was an odd choice for a method that can GIVE, but oh well.

Both of these methods are invoked when a form is submitted. The values you enter in the form will be contained in variables that have the same name as the form elements. Only form elements that have a value entered into them will be passed. The way to get these values, is with the getParameter() method. Whether the values are POSTed or GETed, is entirely up to you. The form tag has an attribute named method. If you specify POST, your form values are available in doPost(), and if you say GET, they're in doGet().

The other way to GET values into the servlet is to 'hard code' them into a link.

For example: if you coded a link like:Then the servlet whose alias is servletName would receive two variables... fName and lName In this specific example, they would be available in the doGet() method of the servlet like:
Hope that helps you out.


[This message has been edited by Mike Curwen (edited September 20, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!