JSP出现了HTTP Status 500 错误,求大神帮忙解决~

wangchuankun1 2014-06-19 03:10:02
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
servlets.AdminLogCheckServlet.doPost(AdminLogCheckServlet.java:60)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.30 logs.
...全文
123 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangchuankun1 2014-06-19
  • 打赏
  • 举报
回复
package servlets;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.JDBCBean;

public class AdminLogCheckServlet extends HttpServlet implements Servlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		
		String result = "";
		JDBCBean jdbc = new JDBCBean();
		
		// 获取用户名
		String username = request.getParameter("username");
		if (username == "" || username == null || username.length() > 20) {
			try {
				result = "请输入用户名(不超过20字符)!";
				request.setAttribute("ErrorUserName", result);
				response.sendRedirect("adminLogin.html");
			} catch (Exception e) {
			}
		}
		// 获取密码
		String password = request.getParameter("password");
		if (password == "" || password == null || password.length() > 20) {
			try {
				result = "请输入密码(不超过20字符)!";
				request.setAttribute("ErrorPassword", result);
				response.sendRedirect("adminLogin.html");
			} catch (Exception e) {
			}
		}

		try {
			// SQL语句
			String sql = "select * from tb_admin where username='" + username
					+ "' and password = '" + password + "'";
			jdbc.rs = jdbc.stmt.executeQuery(sql);// 返回查询结果

		} catch (SQLException e) {

			e.printStackTrace();
		}

		try {
			if (jdbc.rs.next())// 如果记录集非空,表明有匹配的用户名和密码,登陆成功

			{
				// 登录成功后将username设置为session变量的UserName

				// 这样在后面就可以通过 session.getAttribute("username") 来获取用户名,

				// 同时这样还可以作为用户登录与否的判断依据

				request.getSession().setAttribute("username", username);
				response.sendRedirect("login_success.jsp");
			} else {
				// 否则登录失败

				response.sendRedirect("login_failure.jsp");
			}
		} catch (SQLException e) {

			e.printStackTrace();
		}

		try {
			if (null != jdbc.rs) {
				jdbc.rs.close();
			}
			if (null != jdbc.stmt) {
				jdbc.stmt.close();
			}
			if (null != jdbc.connection) {
				jdbc.connection.close();
			}
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}
}

10,606

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧