刚刚接触jsp,请各位指点!为何传过去的用户名和密码都为空,而就直接跳到错误页面!
login.jsp 登陆界面
longin_check 验证界面
login.jsp 登陆界面
<body>
<form name=" form1" method="post" action="Login_check.jsp">
<br>
用户名:
<input type="text" name=" name" id=" name">
</br>
<br>
密码:
<input type="password" name="password" id=" name">
<br>
<input name="Submit" type="submit" id=" Submit" value="登陆">
<input name="Submit2" type="reset" value="重置">
</form>
</body>
longin_check 验证界面
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%
request.setCharacterEncoding("UTF-8");
%>
<%
String name = request.getParameter("name");
String pwd = request.getParameter("password");
try {
Class
.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.print("驱动包连接失败!");
}
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=StuInfor";
String user = "sa";
String password = "sa";
Connection con = null;
PreparedStatement psta = null;
ResultSet rs = null;
String sql = "select * from Student where username='" + name
+ "' and password='" + pwd + "'";
try {
con = DriverManager.getConnection(url, user, password);
} catch (SQLException e) {
e.printStackTrace();
System.out.println("数据库连接失败!");
}
try {
psta = con.prepareStatement(sql);
rs = psta.executeQuery();
if (rs.next()) {
session.setAttribute("Login_name", name); //成功登陆的用户存储到session对象中
response.sendRedirect("Main.jsp"); //登陆成功后转向到mian.jsp页面中
} else {
response.sendRedirect("index.jsp"); //登陆失败转向到index.jsp页面中
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//}
%>
|