String username = request.getParameter("username");
String password = request.getParameter("password");
%>
<%
if (username != null) { //如果用户名不为空,根据它来查试试
try {
%>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(""""");
Statement pstmt = conn.createStatement();
String sql = "select * from w "+" where w_name='" + username + "'" + " and w_password=‘" + password + "’";//查找username。password对应的数据 // pstmt.setString(1,request.getParameter("w_name"));
//pstmt.setString(2,request.getParameter("w_password"));
ResultSet rs = pstmt.executeQuery(sql); // 查询
if(rs.next()) //如果有数据表示可以执行
{ session.setAttribute( "login" , "ok" ); // 验证通过之后,跳转到后续页面
session.setAttribute( "w_name" ,username);
%>
<jsp:forward page="hst5.jsp">
<jsp:param name="" value=""/>
</jsp:forward>
<%
}
else {
%>
<a href="hst1.jsp">账户密码错误,请重新登录</a> <%
} } catch (Exception e) {
e.printStackTrace();
}
}
%
这个一直显示的是空白页面,,在数据库中可以查到信息。不知道为什么。求助~~~~~~~~~~~~~~~
String password = request.getParameter("password");
%>
<%
if (username != null) { //如果用户名不为空,根据它来查试试
try {
%>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(""""");
Statement pstmt = conn.createStatement();
String sql = "select * from w "+" where w_name='" + username + "'" + " and w_password=‘" + password + "’";//查找username。password对应的数据 // pstmt.setString(1,request.getParameter("w_name"));
//pstmt.setString(2,request.getParameter("w_password"));
ResultSet rs = pstmt.executeQuery(sql); // 查询
if(rs.next()) //如果有数据表示可以执行
{ session.setAttribute( "login" , "ok" ); // 验证通过之后,跳转到后续页面
session.setAttribute( "w_name" ,username);
%>
<jsp:forward page="hst5.jsp">
<jsp:param name="" value=""/>
</jsp:forward>
<%
}
else {
%>
<a href="hst1.jsp">账户密码错误,请重新登录</a> <%
} } catch (Exception e) {
e.printStackTrace();
}
}
%
这个一直显示的是空白页面,,在数据库中可以查到信息。不知道为什么。求助~~~~~~~~~~~~~~~
请问你是故意不让我们看、还是没有写url?String username = request.getParameter("username");
这下面随便打印一个信息 看到这个页面没?
System.out.println("pass");我个人感觉是你接收到的username 等于空因为你判断若是进去了 、肯定会有异常显示的、
2、username?什么意思没看懂。我用String username = request.getParameter("username");
这个语句。是来获得,来自上一个jsp文件输入的username和password。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
</body>
</html>
什么都没显示
你这后面打印这句话
System.out.print(username);
看出来值不、
body>
源代码这个中间一直空白
</body>
还是空白页面
你的一堆代码
}else{ out.print("username为null");
}这样加 在页面上就能看了、
但是我运行hst1,jsp 登录时,进入这个界面还是空白的。
这个是我hst1.jsp的文件
<form action="hst.jsp"> 账 号:<input type="text"name="username"><br>
密 码:<input type="password"name="password"><br>
<input type ="submit"name="submit"> 
<a href="hst2.jsp"> 注册</a>
</form>