package com.lh.MyInterceptor;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;public class MyInterceptor implements Interceptor {
public void destroy() {
// TODO Auto-generated method stub

} public void init() {
// TODO Auto-generated method stub

} public String intercept(ActionInvocation invocation) throws Exception {

HttpServletRequest req = ServletActionContext.getRequest();

System.out.println(req.getParameter("username"));
System.out.println(req.getSession().getAttribute("username"));
   if (req.getParameter("username") == null) {
    return Action.LOGIN;
   } else {
    return invocation.invoke();
   } }
}
(菜鸟求教)