严重: 在路径为/201909250329的上下文中,Servlet[jsp]的Servlet.service()引发了具有根本原因的异常/301/login_act.jsp (行.: [4], 列: [1]) useBean类属性[shl.test1.jsp.JspUserDao]的值无效。 应该怎么解决
2条回答 默认 最新
- 无奇不有多 2021-06-30 13:22关注
jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <h1 align="center">系统登陆</h1> <form action="login_act.jsp" method="get"> <table align="center"> <tr> <td>用户名:</td> <td><input type="text" name="name"></td> </tr> <tr> <td>密码:</td> <td><input type="text" name="pwd"></td> </tr> <tr> <td><input type="submit" value="提交"></td> </tr> </table> </form> <% String info = (String) request.getAttribute("info"); %> <%=info == null ? "" : info%> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <jsp:useBean id="user" class="shl.test1.jsp.JspUser"></jsp:useBean> <jsp:useBean id="dao" class="shl.test1.jsp.JspUserDao"></jsp:useBean> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% request.setCharacterEncoding("utf-8"); String name = request.getParameter("name"); String pwd =request.getParameter("pwd"); if(name.equals("")||pwd.equals("")) { //name="";pwd=""; request.setAttribute("info", "请输入用户名!"); %> <jsp:forward page="login.jsp"></jsp:forward> <% } user.setUsername(name); user.setPassword(pwd); if(!dao.login(user)) { request.setAttribute("info", "用户名或密码错误!"); %> <jsp:forward page="login.jsp"></jsp:forward> <% } else { session.setAttribute("user", user); response.sendRedirect("main.jsp"); } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@page import="shl.test1.jsp.JspUser"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <jsp:useBean id="user" class="shl.test1.jsp.JspUser"></jsp:useBean> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% user = (JspUser)session.getAttribute("user"); if(user== null){ request.setAttribute("info", "请登录!"); %> <jsp:forward page="login.jsp"></jsp:forward> <% } %> <input type="button" value="注销" onclick="window.location.href('outlogin.jsp')" /> </body> </html>
package shl.test1.jsp; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class DbConnection { String url = "jdbc:mysql://localhost:3306/jsptest?"+"useUnicode=true&characterEncoding=UTF8"; String user = "root"; String password = ""; static Connection conn ; public static Connection getConnection() { try { Class.forName("com.mysql.jdbc.Driver"); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("Not find Driver!"); } try { conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/jsptest","root",""); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("Not getConnection!"); } System.out.println("Connection is success!"); return conn; } }
package shl.test1.jsp; public class JspUser { private int id; private String username; private String email; private String password; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
package shl.test1.jsp; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; public class JspUserDao { Connection conn = DbConnection.getConnection(); Statement sta; ResultSet rst; public boolean login(JspUser user) { String name = user.getUsername(); String pwd = user.getPassword(); String sql = "select * from jspuser where username='" + name + "' and Password = '" + pwd + "' "; try { sta = conn.createStatement(); } catch (SQLException e) { e.printStackTrace(); System.out.println("sta is not correct "); } try { rst = sta.executeQuery(sql); } catch (SQLException e) { e.printStackTrace(); System.out.println("rst is not correct "); } try { if (rst.next()) { System.out.println("-------login is success ! "); sta.close(); rst.close(); conn.close(); return true; } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; } }
解决 无用评论 打赏 举报
悬赏问题
- ¥30 这是哪个作者做的宝宝起名网站
- ¥60 版本过低apk如何修改可以兼容新的安卓系统
- ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!