关于Servlet的小问题,请大家帮忙,谢谢
大家好,小弟我学JSP没几天,我目前在学Servlet,下面是我的代码首先Login.html如下
<html>
<head>
<title>在线图书XX系统</title>
</head>
<body>
<form action="Login" method="get">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="reset" value="重填"></td>
<td><input type="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
其次Login.java如下
import
import
import javax.servlet.*;
import javax.servlet.http.*;
public class Login extends HttpServlet
{
private String username = "";
private String password = "";
private String inusername = "";
private String inpassword = "";
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
{
//HttpSession session = req.getSession();
//String user = (String)session.getAttribute("user");
username = getInitParameter("username");
password = getInitParameter("password");
inusername = req.getParameter("inusername");
inpassword = req.getParameter("inpassword");
resp.setContentType("text/html; charset=gb2312");
PrintWriter out = resp.getWriter();
if(inusername == null && inpassword == null && inusername.equals("") && inpassword.equals(""))
{
resp.sendRedirect("login.html");
}
else
{
if(inusername.equals(username) && password.equals(password))
{
out.println("<html><head><title>页面提示</title></head>");
out.println("<body>抱歉,网站在建设中,近期期待</body>");
out.println("</html>");
}
else
{
out.println("<html><head><title>页面提示</title></head>");
out.println("<body>请输入正确的用户名和密码<br>");
out.println("<a href" + resp.encodeURL("login.html") + ">请重新登录</a>");
out.println("</body>");
out.println("</html>");
}
}
}
}
再次web.xml如下
<?xml version="1.0" encoding="gb2312"?>
<web-app xmlns="http://java.
xmlns:xsi="http://www.
xsi:schemaLocation="http://java.
http://java.
version="2.4">
<servlet>
<servlet-name>LoginServer</servlet-name>
<servlet-class>Login</servlet-class>
<init-param>
<param-name>username</param-name>
<param-value>shibin</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>1234</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>LoginServer</servlet-name>
<url-pattern>/login.html</url-pattern>
</servlet-mapping>
</web-app>
最后是错误如下:
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
Login.doGet(Login.java:25)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.30 logs.
--------------------------------------------------------------------------------
Apache Tomcat/5.5.30
请问是什么问题啊
[ 本帖最后由 shiboy3 于 2010-8-24 20:00 编辑 ]