servlet的应用
运行jsp页面后提示:java.lang.NullPointerException
com.servlet.LoginCheckServlet.doPost(LoginCheckServlet.java:24)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
文件:LoginCheckServlet。java
package com.servlet;
import com.db.dbutil;
import javax.servlet.*;
import javax.servlet.http.*;
import *;
import java.util.*;
import java.sql.*;
public class LoginCheckServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException,IOException
{
String URL="";
String Username=request.getParameter("username");
String Password=request.getParameter("password");
String sql="select * from t_user where username="+Username+"and password="+Password+"";
dbutil dbto=new dbutil();
ResultSet rs=dbto.executeQuery(sql);
System.out.println(rs);
try{
if(rs.next())
{
URL="1.jsp";
}
else
{
URL="login.jsp";
}
request.getRequestDispatcher(URL).forward(request,response);
}
catch(SQLException e)
{
System.out.println(e.toString());
}
}
}
jsp页面:
<%@ page language="java" contentType="text/html;charset=gb2312"%>
<%@ page import="java.util.*"%>
<html>
<body>
<form action="/LoginCheck" method="post">
用户名:<input type="text " name="username"><br>
密码: <input type="password" name="password"><br>
<input type="submit" value="登录">
</form>
</body>
</html>
web。xml文件:
<web-app xmlns="http://java.
xmlns:xsi="http://www.
xsi:schemaLocation="http://java. http://java.
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>LoginCheckServlet</servlet-name>
<servlet-class>com.servlet.LoginCheckServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginCheckServlet</servlet-name>
<url-pattern>/LoginCheck</url-pattern>
</servlet-mapping>
</web-app>
我是现在是搞不定了 好心人帮帮我啊!小弟谢了!