慕斯卡5552298
2016-10-11 15:12
public String login(){
UsersDAO udo = new UsersDAOImpl();
if (udo.usersLogin(user))
{
//在session中保存登录成功的用户名
// session.setAttribute("loginUserName", user.getUsername());
request.setAttribute("loginUserName", user.getUsername());
return "login_success";
} else {
return "login_failure";
}
}
你的 SuperAction 类是否没有初始化 session 啊,看下面,在 setServletRequest() 有给session 辅助哦:
package action;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;
import com.opensymphony.xwork2.ActionSupport;
//所有Action动作的父类
public class SuperAction extends ActionSupport implements ServletRequestAware,ServletResponseAware,ServletContextAware {
/**
*
*/
private static final long serialVersionUID = 7727505312022359301L;
protected HttpServletRequest request; //请求对象
protected HttpServletResponse response; //响应对象
protected HttpSession session; //会话对象
protected ServletContext application; // 全局对象
@Override
public void setServletContext(ServletContext application) {
this.application = application;
}
@Override
public void setServletResponse(HttpServletResponse response) {
this.response = response;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
this.session = this.request.getSession();
}
}
真给力,非常感谢!
使用Struts2+Hibernate开发学生信息管理功能
80701 学习 · 754 问题
相似问题