
package com.lala.servlets;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class LoginServlet extends HttpServlet{
public void init(ServletConfig sc){
System.out.println("init() login servlet");
}
public void service(HttpServletRequest req,HttpServletResponse res)throws IOException,ServletException{
System.out.println("service() login servlet");
String un=req.getParameter("username");
String pw=req.getParameter("password");
String msg=" ";
if(un.equals(pw)){
msg="Hello"+un+"!your login is sucessful";
}else{
msg="hello"+un+"!your login failed";
}
res.setContentType("text/html");
PrintWriter out=res.getWriter();
System.out.println("<fontsize=6 color=red>"+msg+"<font>");
}
public void destroy(){
System.out.println("destroy() login servlet");
}
}
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException com.lala.servlets.LoginServlet.service(LoginServlet.java:14) javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Dec 26, 2012 1:16:18 PM org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet LoginServlet threw exception java.lang.NullPointerException at com.lala.servlets.LoginServlet.service(LoginServlet.java:14) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454) at java.lang.Thread.run(Unknown Source)

Hello friend
First thing you need to correct is to add a login page. Second thing you are comparing username with password.
if(un.equals(pw)){
You need to do something like this :
if(un.equals(username)&&pw.equals(password)){
Given below the login page 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>Insert title here </title>
</head>
<body>
<form name="myform" action="login" method="post">
<p>User name: <input type="text" name="username"><br>
Password: <input name="password" type="password">
<br>
<input type="submit">
</p>
</form>
</body>
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.