kenny5730
2016-11-23 04:12
HTTP Status 500 - java.lang.NullPointerException
type Exception report
message java.lang.NullPointerException
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:477)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.NullPointerException
user.DAO.UserDao.userLogin(UserDao.java:24)
org.apache.jsp.dologin_jsp._jspService(dologin_jsp.java:109)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.70 logs.
dologin.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<jsp:useBean id="LoginUser" class="user.model.User" scope="page"/>
<jsp:useBean id="UserDao" class="user.DAO.UserDao" scope="page"/>
<<jsp:setProperty property="*" name="LoginUser"/>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
request.setCharacterEncoding("utf-8");//防止中文乱码
if(UserDao.userLogin(LoginUser))
{
session.setAttribute("loginUser",LoginUser.getUsername());//用session对象传递loginUser在success页面显示
request.getRequestDispatcher("login_success.jsp").forward(request, response);//转发
}else
{
response.sendRedirect("login_failure.jsp");//重定向
}
%>
UserDao.java
public class UserDao {
public boolean userLogin(User u) throws SQLException{
String name=u.getUsername();
String pw=u.getPassword();
Connection conn=DBUtil.getConn();
//采用预编译sql语句
StringBuilder sb=new StringBuilder();
sb.append(" select password from users");
sb.append(" where username=?");
PreparedStatement ptmt=conn.prepareStatement(sb.toString());
//传参
ptmt.setString(1, name);
ResultSet res=ptmt.executeQuery();
if(pw.equals(res.getString("password"))){
return true;
}
return false;
}
}
没人救的了你
JAVA遇见HTML——JSP篇
248278 学习 · 3071 问题
相似问题