Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Servlet returns blank page

843841Apr 5 2005
I have a registration page that sends data to the below servlet. The servlet compiled with no errors. However when I press submit at the registration page, the below servlet loads but only returns a blank page. No errors. No exceptions. MySQL database does not get updated. Nothing really stands out as an error in the code. Any ideas ?

First is the registration page code and next is the servlet code. Tks a mil.
<html>
<head>
<title>Create An Account</title>
</head>

<script language = javascript>

function formchecker()
{
 var returnValue = false;
 var usertype = new String ( document.form1.usertype.value);
 var username = new String ( document.form1.username.value);
 var password = document.form1.password.value;
 var retypepassword = document.form1.retypepassword.value;
 var name = new String ( document.form1.name.value);
 var address = new String ( document.form1.address.value);
 var area = document.form1.area.value;
 var phone = document.form1.phone.value;
 var credit = document.form1.credit.value;
 
 var areacheck = /[0-9]{3}/;
 var phonecheck = /[0-9]{7}/;
 var creditcheck = /[0-9]{16}/;

 
 if (username == "")
 {
  alert("All fields MUST be filled. Please complete USERNAME field");
 }
 else if (password == "")
 {
  alert("All fields MUST be filled. Please complete PASSWORD field");
 }
 else if (retypepassword == "")
 {
  alert("All fields MUST be filled. Please complete RETYPE PASSWORD field");
 }
 else if (!(retypepassword == password))
 {
  alert("Password and Re-typed Password do not match. Please correct them");
 }

 else if (name == "")
 {
  alert("All fields MUST be filled. Please complete NAME field");
 }
 else if (address == "")
 {
  alert("All fields MUST be filled. Please complete ADDRESS field");
 }
 else if (!(areacheck.test(area)))
 {
  alert("Please enter a 3 digit phone area code");
  document.form1.area.focus();
  document.form1.area.select();
 }
 else if (!(phonecheck.test(phone)))
 {
  alert("Please enter a 7 digit phone number");
  document.form1.phone.focus();
  document.form1.phone.select();
 }
 else if (!(creditcheck.test(credit)))
 {
  alert("Please enter a 16 digit credit card number with no spaces or dashes");
  document.form1.credit.focus();
  document.form1.credit.select();
 }
 
 else
 {
  returnValue = true;
 }
 
 return returnValue;
}

</script>

<body>
<h1>Establish Your Account</h1>
<p>
<form name="form1" method="get" onsubmit="return formchecker()" action="http://csci571.usc.edu:38018/ass10/RegCheck">
<table>
<tr>
<td>Desired Usertype:</td>
<td><select name=usertype>
	<option selected value=1>Customer
	<option value=2>Admin
</td>
</tr>
<tr>
<td>Desired Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password You Would Like To Use:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>Re-type password:</td>
<td><input type="password" name="retypepassword"></td>
</tr>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Address:</td>
<td><input type="text" name="address" size="40" maxlength="40"></td>
</tr>
<tr>
<td>Phone Area Code (Pls enter a 3 digit number):</td>
<td><input type="text" name="area" size="3" maxlength="3"></td>
</tr>
<tr>
<td>Phone Number (Pls enter a 7 digit number):</td>
<td><input type="text" name="phone" size="7" maxlength="7"></td>
</tr>
<tr>
<td>Credit Card Number (Pls enter a 16 digit number with no spaces or dashes):</td>
<td><input type="text" name="credit" size="16" maxlength="16"></td>
</tr>
</table>
<input type="submit" name="submit" value="Submit">
</form>
</p>
</body>

</html>
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URL;
import java.net.*;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.*;
import java.sql.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class RegCheck extends HttpServlet {

    public void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException {
        
             String usertype = (req.getParameter("usertype"));
    		 String username = (req.getParameter("username"));
    		 String password = (req.getParameter("password"));
    		 String name = (req.getParameter("name"));
    		 String address = (req.getParameter("address"));
    		 String area = (req.getParameter("area"));
    		 String phone = (req.getParameter("phone"));
    		 String credit = (req.getParameter("credit"));
    		 res.setContentType("text/html");
			 PrintWriter out = res.getWriter();
			 try{
    		 Class.forName("com.mysql.jdbc.Driver").newInstance();}
    		 catch (Exception E1) { 
          	 System.err.println("Unable to load driver."); 
             E1.printStackTrace(); 
                }
       try {          
    		 Connection connection = DriverManager.getConnection("jdbc:mysql://csci571.usc.edu:38021/commerce","root","");
       		 Statement statement = connection.createStatement();
       		 String query = "SELECT username from user where usertype="+usertype+" AND username='"+username+"'";
       		 ResultSet result = statement.executeQuery(query);
       		 
       		 if (result.next())
       		 {
       		 	 out.println("<HTML>");
				 out.println("<HEAD><TITLE>Username Error !</TITLE></HEAD>");
				 out.println("<BODY>");
				 out.println("<h1>Username Error !</h1>");
				 out.println("<p>Username already exists. Please enter another username</p>");
				 out.println("<p><a href=\"http://csci571.usc.edu:38018/ass10/signup.jsp\">Return back to registration</a></p>");
			 	 out.println("</BODY></HTML>");
			 }
			 else
			 {
       		 	 String query1 = "insert into user values ("+usertype+",'"+username+"','"+password+"','"+name+"','"+address+"',"+area+","+phone+","+credit+")";
       		 	 statement.executeQuery(query1);
       		 	 out.println("<HTML>");
				 out.println("<HEAD><TITLE>Registration Complete !</TITLE></HEAD>");
				 out.println("<BODY>");
				 out.println("<h1>Registration Complete !</h1>");
				 out.println("<p>Please proceed to main page</p>");
				 if (usertype=="1")
				 {
				 out.println("<p><a href=\"http://csci571.usc.edu:38018/ass10/custmain.jsp\">Customer Main Page</a></p>");
			 	 }
			 	 else
			 	 {
			 	 out.println("<p><a href=\"http://csci571.usc.edu:38018/ass10/adminmain.jsp\">Admin Main Page</a></p>");	 
			 	 }
			 	 out.println("</BODY></HTML>");
			 }
			 connection.close();
		}
            
        catch (SQLException E) { 
           System.out.println("SQLException: " + E.getMessage()); 
           System.out.println("SQLState:     " + E.getSQLState()); 
           System.out.println("VendorError:  " + E.getErrorCode()); 
                }
    }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 3 2005
Added on Apr 5 2005
0 comments
623 views