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!

Servlets not functioning properly/gives blank page

843841Mar 31 2007 — edited Apr 1 2007
Hi there,

My servlets seem to be being tempremental.. they sometimes work, and sometimes they don't - that being within different networks (my home one, and my university one - both wireless).

Could the Internet connection be causing a problem? I am running my website off localhost at the moment so I don't really see how it could be that.

Here is my classpath: C:\tomcat-5.5.17-preconfigured\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\tomcat-5.5.17-preconfigured\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\tomcat-5.5.17-preconfigured\Servlets+JSP;..;..\..;C:\Jconnector\mysql-connector-java-5.0.4\mysql-connector-java-5.0.4-bin.jar;C:\tomcat-5.5.17-preconfigured\apache-tomcat-5.5.17\common\lib\jsp-api.jar;C:\tomcat-5.5.17-preconfigured\apache-tomcat-5.5.17\common\lib\servlet-api.jar;C:\Program Files\Java\jre1.5.0_09\lib\ext\mysql-connector-java-5.0.4-bin.jar

I think it is correct but let me know if I am missing anything, or need to take anything out?

When I run my servlets now, it either returns a blank white page (in which can is doesn't write to the SQL database) and the entered data appears in the URL address bar OR this error appear while user trys to edit their details:

HTTP Status 500

Description: The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
RegisterEditServlet.doGet(RegisterEditServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:419)
org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Secondly, before I was able to compile my servlets by simply entering the path to the file and carrying out the normal Javac procedure, however now I am required to enter the servlet-api.jar path first and then the name of my .java file - why is this??

Somebody please help! Please find one of my servlets below:
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class RegisterEditServlet extends HttpServlet
{
	boolean success = true;
	String error = "";
	
	public void doGet(HttpServletRequest req, HttpServletResponse res)
	{
		// GET PARAMETERS
		String email = req.getParameter("email");
		String pass = req.getParameter("pass");
		String vpass = req.getParameter("vpass");
		String title = req.getParameter("title");
		String fname = req.getParameter("fname");
		String sname = req.getParameter("sname");
		
		// Specify action
		String action = req.getParameter("action");
		error = "";
		success = true;
			
		// VALIDATE THEM
		if((email.equals("")) || (email.indexOf("@") == -1))
		{
			success = false;
			error += "* Email is invalid<br>";
			
		}
		if(((!pass.equals("")) && (vpass.equals(""))) || ((pass.equals("")) && (vpass.equals(""))) || (!pass.equals(vpass)))
		{
			success = false;
			error += "* Password invalid or does not match<br>";
		}
		if(fname.equals(""))
		{
			success = false;
			error += "* You must supply a first name<br>";
		}
		if(sname.equals(""))
		{
			success = false;
			error += "* You must supply a surname<br>";
		}
	
		// SEND INFORMATION BACK
		try
		{
			if(success == true) 
			{
				// Open Connection
				java.sql.Connection cn;
				Statement st = null;
				Class.forName("org.gjt.mm.mysql.Driver");
				cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/bollywoodmm", "root", "ganesh");
				st = cn.createStatement();
			
				
			
				// update the customer record in the database
				if(action.equals("new"))
				{				
			    st.executeUpdate("INSERT INTO customer VALUES(NULL,\"" + email + "\",\"" + pass + "\",\"" + vpass + "\",\"" + title + "\",\"" + fname + "\",\"" + sname + "\")");
				
			
				// REDIRECT?
				res.sendRedirect("http://localhost:3123/bmm/account.jsp?action=regsuccess");
				}
				else
				{
					st.executeUpdate("UPDATE customer SET Password='"+ pass +"',VerifyPassword='"+ vpass +"' WHERE Email_Address='"+ email +"'");
			   	
					// REDIRECT?
					res.sendRedirect("http://localhost:3123/bmm/account.jsp?action=editsuccess");
				}
				
       		}
			else
			{
				if(action.equals("new"))
				{
					res.sendRedirect("http://localhost:3123/bmm/register.jsp?error=" + error + "");
				}
				// send back what was wrong
				res.sendRedirect("http://localhost:3123/bmm/EditDetails.jsp?error=" + error + "");
			}
		}
		catch(Exception e)
  		{ }
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 29 2007
Added on Mar 31 2007
1 comment
199 views