>
> I am using HTML to communicate to a servlet, and I need to be able to
> go back and forth between HTML and the servlet to progress through this
> user interactive application. I login using an HTML form with text
> fields, invoke the servlet, verify the login using JDBC and, once
> verified as a valid login, I use the PrintWriter to output a selectable
> HTML list back to HTML. I then select the list item and click on the
> process button. This is the form within which the list named
> configtables is created:
>
> out.println("<form method=GET
> action='http://155.108.86.200:8000/servlet/LoginServlet'>");
>
> That's where I am stuck. In my doGet(HttpServletRequest,
> HttpServletResponse) function within the servlet I try to see the
> select list item using:
>
> String values[] = req.getParameterValues("configtable");
>
> I get the error:
>
> 500 Internal Server Error
> LoginServlet:
> java.lang.NullPointerException
>
>
Ok if you want the servlet to handle multiple forms you should use a session
object
to store a counter in it which 'reminds' your service method what it should
do next.
The problem is that you are trying to retrieve the value of the configtable
parameter when it may be that none exists (hence the error).
so at the beginning of your doGet method do the following
HttpSession session = req.getSession(true);
if(session.isNew()) { // Brand spanking new session
session.putValue("stage", new Integer(0));
}
then in the processing bit do something funky with a switch....
int stage = ((Integer)session.getValue("stage")).intValue();
switch(stage) {
case 0 : { // Your login bit then....
// Output the next form (configtable)
session.putValue("stage", new Integer(++stage));
case 1 : { // now do your thing with the configtable
String[] values = req.getParameterValues("configtable");
// Process stuff, output next form
session.putValue("stage", new Integer(++stage));
case 2 : // Keep going until you have an enormous servlet :)
default : // Boom
}
Don't forget to sprinkle breaks in there of course.
Hope this helps you on your way
Andy Bailey
PS I can't guarantee that the code above will work as is because I just
hacked
it into the mail but I use similar setups for servlets that can process
multiple
forms. Another solution is to send a hidden input field in each form, call
it "stage"
and grab the value thus...
String stageS = req.getParameter("stage");
// convert to integer and proceed as above
I have another, more complicated, scheme which involves a Hashtable and a
method which
checks the command order because the http information I am processing must
be done in
a certain order, has to be hacker safe and involves database transactions.
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html