Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

jsp form validation

Status
Not open for further replies.

treds2000

Programmer
Mar 24, 2003
2
GB
im trying to validate a user sign up form.

The jsp page submits the values to a vailidateRegister servlet which then if the form fields contain relevent data it directs it on to another servlet which then stores the details in a database. However, even with relevent data in fields it redirects me back to the register.jsp (form) page and does not submit data to the insert servlet
hope this is enough description

any ideas

heres the code for the validation servlet (where i think the problem is)

import java.io.*;
import java.sql.*;
import java.lang.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class validateRegister extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
String strName = req.getParameter("Name");
String strEmail = req.getParameter("Email");
String strPhone = req.getParameter("Phone");
String strPassword = req.getParameter("Password");
String strPassword2 = req.getParameter("Password2");
String strPostCode = req.getParameter("PostCode");

String strError = "";
PrintWriter out = res.getWriter();

out.println(&quot;<html>&quot;);
out.println(&quot;<boby>&quot;);

if ((strName == null) || (strName.length() == 0)){
strError +=&quot; !You must enter a valid Name ! &quot;;}
if ((strEmail == null) || (strEmail.length() == 0)){
strError +=&quot; !You must enter a valid Email ! &quot;;}
if ((strPhone == null) || (strPhone.length() == 0)){
strError +=&quot; !You must enter a valid Phone Number ! &quot;;}
if((strPassword == null) || (strPassword.length() == 0)){
strError +=&quot; !You must enter a Password ! &quot;;}
if((strPassword != strPassword2)){
strError +=&quot; !The Password confirmation you entered is not correct ! &quot;;}


if (strError.length() < 0)
{
RequestDispatcher rd = req.getRequestDispatcher(&quot;../servlet/register?Name=&quot; + strName +
&quot;&Email&quot; + strEmail + &quot;&Phone&quot;+ strPhone + &quot;&PostCode&quot; + strPostCode +&quot;&Password&quot; + strPassword);
rd.forward(req, res);


}
else
{
out.println(&quot;error&quot;);

res.sendRedirect(&quot;../servlet/register.jsp?Name=&quot; +strName +
&quot;&Email&quot; + strEmail + &quot;&Phone&quot;+ strPhone + &quot;&PostCode&quot; + strPostCode);
}

out.println(&quot;</body>&quot;);
out.println(&quot;</html>&quot;);



}
public void doPost(HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException {
doGet(req, res);
}

}
 
My first question is why are u doing out.print inbetween the processing?

Second give a return statement after the forward and sendRedirect calls.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top