在下面那段代码中
6. <%
7. Connection conn = null;
8. try {
9. conn = DBConnection.getConnection();
10. PreparedStatement pStat = conn.prepareStatement(
11. "select USER_NAME from T_USER where USER_ID=? and password = ?");
12. pStat.setString(1, userBean.getUserId());
13. pStat.setString(2, userBean.getPassword());
14. ResultSet rs = pStat.executeQuery();
15. if (rs.next()) { //密码正确
16. userBean.setUserName(rs.getString(1));//设置用户名
17. session.setAttribute("ses_userBean", userBean);//将userBean放入Session对象中
18. %><jsp:forward page=" welcome.jsp "></jsp:forward>
19. <%} else { //密码错误%>
20. <jsp:forward page="fail.jsp"></jsp:forward>
21. <%
22. }} finally {
23. if(conn != null) conn.close();
24. }
25. %>
我想问的是:
1 里面的第19行 <%} else { //密码错误%> 为什么要在}else{前加入<% %>,能不加么?请大家解释一下,我刚刚学JSP
2 .if (rs.next()) { //密码正确 rs难道不是指向查询结果中的第一条记录么?为什么是下一条不为空才是密码正确呢?
6. <%
7. Connection conn = null;
8. try {
9. conn = DBConnection.getConnection();
10. PreparedStatement pStat = conn.prepareStatement(
11. "select USER_NAME from T_USER where USER_ID=? and password = ?");
12. pStat.setString(1, userBean.getUserId());
13. pStat.setString(2, userBean.getPassword());
14. ResultSet rs = pStat.executeQuery();
15. if (rs.next()) { //密码正确
16. userBean.setUserName(rs.getString(1));//设置用户名
17. session.setAttribute("ses_userBean", userBean);//将userBean放入Session对象中
18. %><jsp:forward page=" welcome.jsp "></jsp:forward>
19. <%} else { //密码错误%>
20. <jsp:forward page="fail.jsp"></jsp:forward>
21. <%
22. }} finally {
23. if(conn != null) conn.close();
24. }
25. %>
我想问的是:
1 里面的第19行 <%} else { //密码错误%> 为什么要在}else{前加入<% %>,能不加么?请大家解释一下,我刚刚学JSP
2 .if (rs.next()) { //密码正确 rs难道不是指向查询结果中的第一条记录么?为什么是下一条不为空才是密码正确呢?
解决方案 »
- Java开发Web网站太迷茫了,N多的框架如何选择才好
- 我的servlet为什么不能运行
- 求ubuntu 7.10 原始sources.list文件
- 求struts环境配置
- 如何在JSP页面中嵌套公式编辑器
- 怎么编写一个登入验证页面?要求1.密码:6个字符(字母和数字混排)2.符合条件后转入另一个页面
- jsp连接mysql数据库驱动,用何种方式。
- 关于Hibernate 与数据库查询问题。
- 春节礼物--中文web-app_2_3.dtd
- 为什么submit提交后调用servlet中的Find.class,总是显示原先编译的结果,而新编译后却显示部出来?
- 如何解决运行一个程序,多次开关数据连接的问题?附代码
- 页面跳转
1.else 是一段java 代码,当然因该写在<%%>中。否则,如何识别。
2.rs的指针的位置在第一个结果之前,beforeFirst,所以第一个结果应该用next().