<body>
<%
String strName=request.getParameter("userName");
String strPass=request.getParameter("userPass");
if("".equals(strName)||"".equals(strPass)){
%>
<script>
alert("用户名或者密码为空");
</script>
<%
}
else{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracl:thin:@localhost:1521:orcl","admin","sa");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select name,password from test where name='"+strName+"'");
if(rs.next()){
if(rs.getString("password").equals(strPass)){
response.sendRedirect("index.jsp");
}
}
}
%>
<form action="login.jsp" method="post">
<table>
<tr>
<td>用户名</td><td><input id="userName" type="text"/></td>
</tr>
<tr>
<td>密码</td><td><input id="userPass" type="text"/></td>
</tr>
<tr>
<td colspan="2"><input value="登录" type="submit"/><input value="取消" type="reset"/></td>
</tr>
</table>
</form>
</body>
点击按钮没有任何反应,也没有跳转呢?
<%
String strName=request.getParameter("userName");
String strPass=request.getParameter("userPass");
if("".equals(strName)||"".equals(strPass)){
%>
<script>
alert("用户名或者密码为空");
</script>
<%
}
else{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracl:thin:@localhost:1521:orcl","admin","sa");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select name,password from test where name='"+strName+"'");
if(rs.next()){
if(rs.getString("password").equals(strPass)){
response.sendRedirect("index.jsp");
}
}
}
%>
<form action="login.jsp" method="post">
<table>
<tr>
<td>用户名</td><td><input id="userName" type="text"/></td>
</tr>
<tr>
<td>密码</td><td><input id="userPass" type="text"/></td>
</tr>
<tr>
<td colspan="2"><input value="登录" type="submit"/><input value="取消" type="reset"/></td>
</tr>
</table>
</form>
</body>
点击按钮没有任何反应,也没有跳转呢?
String strName=request.getParameter("userName");
String strPass=request.getParameter("userPass");
strName和strPass应该都是null值吧,也就是说你页面刚载入就执行数据库操作了
<input id="userName" type="text"/>和<input id="userPass" type="text"/>
改为<input name="userName" type="text"/>和<input name="userPass" type="text"/>
if("".equals(strName)||"".equals(strPass)){
改成
if(strName==null||strPass==null){
试试吧
<%
String strName=request.getParameter("userName");
String strPass=request.getParameter("userPass");
if(strName.equals(""))||strPass.equals("")){
out.print("用户名或者密码为空");
}
else{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracl:thin:@localhost:1521:orcl","admin","sa");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select name,password from test where name='"+strName+"'");
while(rs.next()){
if(rs.getString("password").equals(strPass)&&rs.getString("name").equals(strName)){
response.sendRedirect("index.jsp");
}
}
}
%>
<form action="login.jsp" method="post">
<table>
<tr>
<td>用户名</td><td><input id="userName" name="userName"type="text"/></td>
</tr>
<tr>
<td>密码</td><td><input id="userPass" name="userpass" type="text"/></td>
</tr>
<tr>
<td colspan="2"><input value="登录" type="submit"/><input value="取消" type="reset"/></td>
</tr>
</table>
</form>
楼上的你要借鉴,你都写错了,肯定获取不到了,在你将上述修改完成以后呢,
你这样写的话,是可定不行的,你想想看,你在login.jsp中写form表单有提交给自己并获得自己提交的值,可是你想过没有,其实你提交的值已经能够传递过去了,但是你提交的页面却又是login.jsp,结果getParameter(“”)时获取的就不是你提交的值了,而是你这个页面中的form表单的元素值,可是提交跳转后的值为空(<input id="userName" name="userName"type="text"/><input id="userPass" name="userpass" type="text"/>) 所以你会看到的一直是执行“点击按钮没有任何反应,也没有跳转呢?” 呵呵……