菜鸟,急等高手回答!!!

菜鸟,急等高手回答!!!

我的LoginServlet.java 程序如下 :
Java code
 
public class LoginServlet extends HttpServlet { public void init(){ } public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ boolean success = false; String userName=request.getParameter("userName"); String passWord=request.getParameter("passWord"); if(userName.equals(this.getInitParameter("userName"))){ if(passWord.equals(getInitParameter("passWord"))){ success=true; } } if(success){ HttpSession session =request.getSession(true); session.setAttribute("userName",userName); response.sendRedirect("/myPrj/state/cookie"); }else{ response.sendRedirect("/myPrj/state/login.html"); } } public void destroy(){ } public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{ } }
 


login.html部分文件内容如下:

HTML code
 
<form method="post" action="/myPrj/state/login"> <table align="center" cellspacing ="1" cellpadding="3" border="1" width="350" > <tr> <td align ="center"> userName</td> <td> <input type ="text" name="userName " size="15" maxlength="8" value=""> </td> </tr> <tr> <td align ="center"> passWord</td> <td> <input type ="text" name="passWord " size="15" maxlength="8" value="" > </td> </tr> </table> <br> <center> <input type="submit" value = "login"> </center> </form>
 


我的部分web.xml文件如下:
XML code
 
<servlet> <servlet-name>login</servlet-name> <servlet-class>filter.LoginServlet</servlet-class> <init-param> <param-name>userName</param-name> <param-value>tony</param-value> <param-name>passWord</param-name> <param-value>123</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>login</servlet-name> <url-pattern>/state/login</url-pattern> </servlet-mapping>
 


报错信息是:

type Exception report

message

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

exception

java.lang.NullPointerException
filter.LoginServlet.doPost(LoginServlet.java:33)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.


请大侠们帮帮忙!!谢谢啦,看看那里错了 !!!
俺水平太低,看不懂你是怎么错的。
能不能把你的调试过程完整的说一边啊?


不懂,up
不懂,up
java.lang.NullPointerException
空指针异常,肯定就是你的doPost方法中有值没有传过去。你用debug查一下,看看那个地方值是空的。
检查这部分
String userName=request.getParameter("userName");
        String passWord=request.getParameter("passWord");
       
        if(userName.equals(this.getInitParameter("userName"))){
                if(passWord.equals(getInitParameter("passWord"))){
                success=true;
            }
        }
看那个值没有取到