📄 registerinteceptor.java
字号:
package com.test.interceptor;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.StrutsStatics;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.test.bean.UserBean;
import com.test.service.UserService;
import com.test.service.impl.UserServiceImpl;
public class RegisterInteceptor extends AbstractInterceptor {
private UserService userService;
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
System.out.println("register inteceptor_1");
HttpServletRequest rq = (HttpServletRequest) ActionContext.getContext()
.get(StrutsStatics.HTTP_REQUEST);
HttpServletResponse rp = (HttpServletResponse) ActionContext
.getContext().get(StrutsStatics.HTTP_RESPONSE);
// HttpSession session = rq.getSession();
rq.setCharacterEncoding("UTF-8");
rp.setCharacterEncoding("UTF-8");
Map map = (Map) ActionContext.getContext().getSession();
Cookie[] cookies = rq.getCookies();
//�������
/*for(Iterator it = map.keySet().iterator();it.hasNext();){
String key = (String)it.next();
System.out.println("RegisterInteceptor_sessionKey="+key);
System.out.println("RegisterInteceptor_sessionValue="+(map.get(key)));
}*/
System.out.println("RegisterInteceptor_sessionMap="+map.get("userBean"));
for(Cookie cookie : cookies){
System.out.println("RegisterInteceptor_cookieName="+cookie.getName());
System.out.println("RegisterInteceptor_cookieValue="+URLDecoder.decode(cookie.getValue(),"UTF-8"));
}
//�������
Map<String, String> cookieMap = new HashMap<String, String>();
if (map == null) {
return invocation.invoke();
} else {
if (map.get("userBean") != null) {
return "alreadyRegister";
} else {
if(cookies!=null){
for (Cookie cookie : cookies) {
cookieMap.put(cookie.getName(), URLDecoder.decode(cookie.getValue(),"UTF-8"));
}
String userName = cookieMap.get("username");
String password = cookieMap.get("password");
if (userService.loginJugeMent(userName, password)) {
return "alreadyRegister";
} else {
// System.out.println("registerIntecepter="+invocation.invoke());
return invocation.invoke();
}
}else{
return invocation.invoke();
}
}
}
}
public UserService getUserService() {
return userService;
}
public void setUserService(UserService userService) {
this.userService = userService;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -