login.jsp中按下登陆 form跳转时出现500错误
<%@ page language="java" import="java.util.*,java.sql.*"pageEncoding="gbk"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
request.setCharacterEncoding("gb2312");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:teashop",
"sa", "");
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;//声明结果集rs
//--------------------------------------------------------
String op = request.getParameter("op");
if (op != null && op.equals("exit")) {
session.removeAttribute("userid");
session.removeAttribute("cart");
response.sendRedirect("cust/index.jsp");
}
if (op != null && op.equals("login")) {
String s_userid = request.getParameter("userid");
String s_password = request.getParameter("password");
String s_select = "select * from user where userid='"
+ s_userid + "' and password='" + s_password + "'";
rs = stmt.executeQuery(s_select);
if (rs.next()) {
//有用户信息
session.setAttribute("userid", s_userid);
response.sendRedirect("index.jsp");
} else {
//无此用户信息
String temp = "您输入的用户名或密码错误,请重新输入。返回!";
temp = (temp.toString(), "gbk");
response.sendRedirect("error.jsp?errormessage=" + temp);
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>登陆</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="maincss.css">
<script type="text/javascript">
function checksubmit() {
if (document.loginform.userid.value == "") {
alert("用户名不能为空");
document.loginform.userid.focus();
return false;
}
if (document.loginform.password.value == "") {
alert("密码不能为空");
document.loginform.password.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<%
String s_userid = (String) session.getAttribute("userid");
if (s_userid == null) {
%>
<form name="loginform" action="cust/login.jsp?op=login" method="post">
<table width=100% cellspacing=0 cellpadding=5 border=0 class=td>
</tr>
<tr height=25%>
<td>
用户名
</td>
<td>
<input name="userid" type="text" class=formtext size=15 />
</td>
</tr>
<tr height=25%>
<td>
密码
</td>
<td>
<input name="password" type="password" class=formtext size=15 />
</td>
</tr>
<tr>
<td>
<input name="loginbutton" type="submit" value="登陆"
onclick="return checksubmit();" />
</td>
<td>
<a href="cust/register.jsp">新用户注册</a>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</form>
<%
} else {
%>
<table class=td border=0 width=100% cellspacing=0 cellpadding=0
bgcolor=#f6f6f6>
<tr>
<td><%=s_userid%>您好!
<br />
欢迎来到茶坊 官网!
<br />
<br />
<a href="cust/passwordedit.jsp">修改登录密码</a>
<br />
<a href="cust/userinfoedit.jsp">维护个人信息</a>
<br />
<a href="cust/myorder.jsp">查看历史订单</a>
<br />
<a href="cust/shoppingcart.jsp">查看购物车</a>
<br />
<a href="cust/leaveword.jsp">给管理员留言</a>
<br />
<a href="cust/index.jsp?op=exit">注销退出</a>
<br />
</td>
</tr>
</table>
<%
}
%>
</body>
</html>
exception
org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
root cause
java.lang.NullPointerException
org.apache.jsp.cust.MyJsp_jsp._jspService(MyJsp_jsp.java:51)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)