1.先建立一个Action
package com.jane.strutsdemo.actionbase;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public abstract class Auth extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(request.getSession().getAttribute("user")==null){
return new ActionForward("/error.jsp");
}
return doExecute(mapping,form,request,response);
}
public abstract ActionForward doExecute(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) ;
}
2.在建立一个Action来继承上面的Action
package com.jane.strutsdemo.struts.action;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.jane.strutsdemo.actionbase.Auth;
public class LoginAction extends Auth {
public ActionForward doExecute(ActionMapping mapping,
ActionForm actionForm, HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub
return mapping.findForward("success");
}
}
3.配置Struts_config.xml文件,只需要配置子类Action和From就可以了
 |
文件: |
StrutsDemo.rar |
大小: |
19KB |
下载: |
下载 | |
还有一种就是继承的DispatchAction
阅读(1232) | 评论(0) | 转发(0) |