liujiajiran 2018-09-28 01:12 采纳率: 0%
浏览 3164

用struts2完成连接数据库实现用户登录注册功能;

注册功能实现了,也存进数据库了,但跳转到登录页面就无法成功登录,一直跳到登录不成功的页面。这是为啥?
//链接数据库的方法
public class Conn {
Connection conn = null;
Statement st = null;
ResultSet rs = null;
public Connection getConn(){
try{
Class.forName("org.gjt.mm.mysql.Driver");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mytest","root","123456");
st = conn.createStatement();
}catch(Exception e){
e.printStackTrace();;
}
return conn;
}
// 处理登录的方法
public String loginMethod(){
try{
String sql1 = "select * from user where username=' "+getUsername()+" ' and password=' "+getPassword()+" '";
PreparedStatement pst=conn.getConn().prepareStatement(sql1);
ResultSet rs=pst.executeQuery();
if(rs.next()){
ActionContext.getContext().getSession().put("user",username );
return "loginin";
}else{
this.addFieldError("error", "用户名或密码错误!!");
return "loginout";
}
}catch(Exception e){
e.printStackTrace();
return "loginout";
}

// stuuts.xml配置


UserLogin.jsp
WelcomeLo.jsp

// UserLogin.jsp页面



/s:fielderror

请您输入用户名与密码





/s:form


WelcomeLo.jsp页面


欢迎${sessionScope.user},您已经登录!


  • 写回答

2条回答

  • dabocaiqq 2018-09-28 02:05
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧