When a servlet calls itself based on a form action,
1. When HTML calls servlet the first time it works fine.
2. Subsequently when the servlet calls itself using post, it fails when
this
request.getParameterValues("TEXT1");
gets reexecuted. When this line is commented the Servlet is successful
but the purpose
is not solved.
Our aim is to basically, make the servlet add more lines to a HTML table
for input on
request, retaining all the current values in the HTML table.
Java Servlet Code:
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorldExample extends HttpServlet {
int i;
int count = 0;
String[] textarray;
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
int i;
count = count + 1;
out.flush();
out.println("<html>");
out.println("<body bgcolor=\"white\">");
out.println("<head>");
out.println("</head>");
out.println("<body>");
out.println("<FORM
action=http://localhost:8080/servlet/HelloWorldExample method=post>");
textarray = request.getParameterValues("TEXT1");
for(i = 0;i <= textarray.length - 1;i++)
{
out.println("<Input type=Text name=text1
value="+textarray[i]+">") ;
out.println("<BR>");
}
out.println("<Input type=submit>");
out.println("</FORM>");
out.println("</body>");
out.println("</html>");
out.close();
}
}
The HTML Which invokes the servlet first time:
<SCRIPT language=javascript>
function sethidden()
{
form1.hidden1.value="1";
form1.submit();
}
</Script>
<BODY>
<FORM name=form1 method =post
action="http://localhost:8080/servlet/HelloWorldExample">
<TABLE id=table1>
<TR>
<TD> <INPUT TYPE=TEXT NAME="TEXT1"></TD>
</TR>
<TR>
<TD> <INPUT TYPE=TEXT NAME="TEXT1"></TD>
</TR>
</TABLE>
<INPUT TYPE=button name =button1 value=add onclick="sethidden()">
<INPUT type=text name=hidden1 value = '0'>
</FORM>
</BODY>
___________________________________________________________________________
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