在检测页面写 <% if(session.getAttribute( "stuNumber") == null) { response.sendRedirect( "/Sign_Up_System/qiantai/login.jsp "); } %> LoginAction.java代码如下 package com.sign_up.action; import javax.servlet.http.HttpServletRequest; import org.apache.struts2.interceptor.ServletRequestAware; import com.opensymphony.xwork2.ActionSupport; import com.sign_up.bean.Xuesheng; import com.sign_up.dao.StuManage; public class StuLoginAction extends ActionSupport implements ServletRequestAware{ private static final long serialVersionUID = 1L; private String stuNumber; private String password; private Integer stuId; private String stuName; private StuManage stuManage; private HttpServletRequest request; public String getStuNumber() { return stuNumber; } public void setStuNumber(String stuNumber) { this.stuNumber = stuNumber; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String execute(){ String page = "fail"; Xuesheng xuesheng = stuManage.checkUser(stuNumber, password); if(xuesheng!=null){ stuId=xuesheng.getStuId(); stuName=xuesheng.getStuName(); request.getSession().setAttribute("stuNumber",stuNumber); System.out.println(stuNumber); page = "success"; }return page; } public Integer getStuId() { return stuId; } public void setStuId(Integer stuId) { this.stuId = stuId; } public StuManage getStuManage() { return stuManage; } public void setStuManage(StuManage stuManage) { this.stuManage = stuManage; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public void setServletRequest(HttpServletRequest request) { // TODO Auto-generated method stub this.request = request; } }