www.webdeveloper.com
Results 1 to 6 of 6

Thread: Error with the Servlet page

  1. #1
    Join Date
    Nov 2013
    Posts
    69

    Error with the Servlet page

    If anyone could help me figure out what is going on with this, I would be grateful. I can't figure out why I am getting the error below. I have also included the servlet file, the xml file and the jsp file.
    This is the very first time I have worked with JSP and Servlets so I am sort of lost.

    Code:
    HTTP Status 500 - 
    
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: Error instantiating servlet class airline.servlets.Login
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	java.lang.Thread.run(Unknown Source)
    
    root cause
    
    java.lang.ClassNotFoundException: airline.servlets.Login
    	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    	org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	java.lang.Thread.run(Unknown Source)
    
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.

    XML file
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    	<display-name>Flight</display-name>
    	<servlet>
    		<description>
    		</description>
    		<display-name>Login</display-name>
    		<servlet-name>Login</servlet-name>
    		<servlet-class>airline.servlets.Login</servlet-class>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>Login</servlet-name>
    		<url-pattern>/Login</url-pattern>
    	</servlet-mapping>
    	
    </web-app>
    JSP file
    Code:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    	<head>
    		<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    		<title> Login Page</title>
    	</head>
    	
    	<body>
    		<h1>Awesome Airlines</h1>
    		<h2>Login Page</h2>
    		<form action='${pageContext.request.contextPath}/Login' method='post'>
    			<fieldset>
    				
    						<label for='usrName'>User Name:</label>
    						<input id='usrName' name='usrName' type='text'>
    					
    						<label for='passwd'>Password:</label>
    						<input id='passwd' name='passwd' type='password'>
    					
    						<input type='submit' value='Log In'>
    					
    				</fieldset>
    		</form>
    
    
    	</body>
    </html>
    Servlet file
    Code:
    package airline.servlets;
    
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Enumeration;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import airline.javas.Users;
    
    /**
     * Servlet implementation class login
     */
    public class Login extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
        public Login() {
            super();
            // TODO Auto-generated constructor stub
        }
    
    	/**
    	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		
    		doPost(request, response);
    	}
    
    	/**
    	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
    	 */
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		// TODO Auto-generated method stub
    		String usrname, passwd;
    		boolean exists;
    		Users obj = new Users();
    		usrname = request.getParameter("usrName");
    		passwd = request.getParameter("passwd");
    		
    		exists = obj.userExist(usrname, passwd);
    		
    		 response.setContentType("text/html");
    		 PrintWriter out = response.getWriter();
    		 String docType =
    			      "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    			      "Transitional//EN\">\n";
    		
    		
    		if(exists)
    		{
    			 out.println(docType +
    		                "<HTML>\n" +
    		                "<HEAD><TITLE>" + "Registered user" + "</TITLE></HEAD>\n" +
    		                "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    		                "<H1 ALIGN=CENTER>" + "Welcome  " + "   "+usrname + "</H1>\n" +
    		                "<TABLE BORDER=1 ALIGN=CENTER>\n" +
    		                "<TR BGCOLOR=\"#FFAD00\">\n" +
    		                "<TH>Parameter Name<TH>Parameter Value(s)");
    			
    			
    		}
    		else
    		{
    			
    			handleRequest(request, response);
    		/*	 out.println(docType +
    		                "<HTML>\n" +
    		                "<HEAD><TITLE>" + "Un-Registered user" + "</TITLE></HEAD>\n" +
    		                "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    		                "<H1 ALIGN=CENTER>" + "Failed!" + "</H1>\n" +
    		                "<TABLE BORDER=1 ALIGN=CENTER>\n" +
    		                "<TR BGCOLOR=\"#FFAD00\">\n" +
    		                "<TH>Parameter Name<TH>Parameter Value(s)");
    			 */
    			 
    			
    			
    		}
    		
    		
    		out.close();
    	}
    	
    	public void handleRequest(HttpServletRequest req, HttpServletResponse res) throws IOException {
    			 
    			        PrintWriter out = res.getWriter();
    			        res.setContentType("text/plain");
    			 
    			        Enumeration<String> headerNames = req.getHeaderNames();
    			 
    			        while (headerNames.hasMoreElements()) {
    			 
    			            String headerName = headerNames.nextElement();
    			            out.write(headerName);
    			            out.write("\n");
    			 
    			            Enumeration<String> headers = req.getHeaders(headerName);
    			            while (headers.hasMoreElements()) {
    			                String headerValue = headers.nextElement();
    			                out.write("t" + headerValue);
    			                out.write("\n");
    			            }
    			 
    			        }
    			 
    			        out.close();
    			 
    			    }	
    
    }

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    seems like you are missing servlet.jar library...which server u are using?
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Nov 2013
    Posts
    69
    Tomcat

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    can you post an listing of content of your deployment folder on tomcat for this servlet?
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  5. #5
    Join Date
    Nov 2013
    Posts
    69
    So I am not sure what happened because I didn't do anything, I don't think anyway, but it is working now.

  6. #6
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    good..:-)
    If I were you, I would make sure to find out what was the issue...:-)
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles