• Post Reply Bookmark Topic Watch Topic
  • New Topic

Mommy, where do parameters come from?

 
Carol Murphy
village idiot
Bartender
Posts: 1203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm doing one of the Servlet assignments on the Cattle Drive, and I have no book on Servlets, so I am doing a lot of my coding by fumbling around in the dark.
The assignment involves passwords and session handling and creating a session ID that gets passed into all html documents generated by the servlet before allowing them to be displayed.
My question is this: Does a parameter have to exist as the value in one of the components of a form before it can be passed from servlet to servlet using parms.getString( "whatever" )?
(This method call may only make sense to those doing the cattle drive servlets assignments.)
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marty Hall put his book Core Servlets and JavaServer Pages online... that might help you out!
 
Rick Salsa
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carol Murphy:
My question is this: Does a parameter have to exist as the value in one of the components of a form before it can be passed from servlet to servlet using parms.getString( "whatever" )?
(This method call may only make sense to those doing the cattle drive servlets assignments.)

No, not necessarily. It could come from a link:

This will send a parameter called "whatever" with the value of "foo" to the servlet using GET. Parameters that come from forms are usually sent using POST. I'd get Marty's book, like Jessica suggested. It was my first servlet book. It's excellent!!
HTH,
/rick
[ April 25, 2002: Message edited by: rick salsa ]
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will be better of getting hold of a book quickly. The link to Marty Hall's book posted by Jessica is definitely helpful. You can also check sun's site to the Servlet tutorial.
 
Ruilin Yang
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to pass values among servlets or JSP is by using javaBeans. These java beans serve as value objects and stored in the session , then the values in the java bean can be retrieved whenever you need them.
 
daryl olson
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your statement, "before it can be passed from servlet to servlet using parms.getString( "whatever" )?" I understand that you want to do a forward from one servlet to another servlet but set an addtional parameter value before doing so.
If my understanding is correct then use request.setAttribute(String name, Object object) before you forward to the next Servlet. Object could be a JavaBean and hold multiple values.
In the "forwarded to" servlet, use request.getAttribute(String name) to retrieve the value(s), remembering to cast the returned value to the appropriate type.
Daryl
 
Ruilin Yang
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you got right mostly. If you use javaBean as value object, you do not need to cost the individual values (attributes). You only need to cast the javaBean object to the type of the javaBean class.
good luck
 
Marilyn de Queiroz
Sheriff
Posts: 9079
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-Session-Tracking.html
http://novocode.de/doc/servlet-essentials/chapter4b.html#4_5
[ April 25, 2002: Message edited by: Marilyn deQueiroz ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!