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.
The scriptlets in your JSP* execute on the server long before the resulting HTML is sent to the browser, where the form elements are interpreted, presented to the user, and allow input. Trying to get those value before they even exist obviously is not going to work. You might want to check out this article for a run-down on how JSP operates.
To deal with the form values, you need to submit the form to a servlet where the values can be processed.
* Scriptlets are over 6 years out-of-date. You should be concentrating on using modern technology in your JSPs' namely, the JSTL and EL.
What you describe is exactly my understanding; but I did find an example on the web where someone was doing just what I have described.
As you know, the entire code was not there, but the indication was that you could do this. I thought I was just not doing it "right" and that
was the reason my attempt was failing. See replies 3, 4, and 5 to http://forums-beta.sun.com/thread.jspa?messageID=1146080.
Most likely what you are seeing is a JSP with a form that submits to the same JSP. The second time around, the values will be there, but obviously not the first.
That's a very old-fashioned and discredited practice that you should not be following. Here's another article that details modern web app structures.
It sounds as if you are finding some very old information on the web that's very outdated and leading you down the path of poor and outdated practices.
Joined: Sep 11, 2000
Is there a simple way to direct a jsp to one of two pages depending on user input without going to the servlet? I'm going to read every article suggested; but meanwhile, the object is to do one of two things. After choosing the thing I want to do, then I need to display a page to get more information before actually performing the action. Do I need two servlets then so I go to two different doPost methods, one after the initial choice and another when the details are provided?
My thought was to forward to the initial choice and then get the details; but I can't do that without going through a servlet. Do I need another servlet then to process the details?
But if that's a bit advanced for the time being, you can cause the action of a form to change prior to submission so that the redirect will be to the appropriate "next" page (hint: via an onsubmit handler).
Joined: Sep 11, 2000
Actually, I need a new input page I think for the "extra" information as the information is quite different for the two options; could look quite messy to have both on the same page. Here is where an "include" could come in handy I guess. Hmmm....