📄 notloggedonexceptionhandler.java
字号:
package com.leeman.wkexs.common.security;
import java.util.Locale;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpSession;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ExceptionHandler;
import org.apache.struts.config.ExceptionConfig;
import org.apache.struts.Globals;
import com.leeman.wkexs.web.base.*;
public class NotLoggedOnExceptionHandler extends ExceptionHandler{
public ActionForward execute(
Exception ex,
ExceptionConfig ae,
ActionMapping mapping,
ActionForm formInstance,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException{
HttpSession session = request.getSession();
String langid = (String)session.getAttribute(BaseConstants.SESSION_LANG_ID);
Cookie cookie[] = request.getCookies();
int cookie_length = 0;
if(cookie != null)
{
cookie_length = cookie.length;
}
System.out.println("cookielength:" + cookie_length);
for(int i=0; i<cookie_length; i++){
System.out.println(cookie[i].getName() + "=" + cookie[i].getValue());
if(cookie[i].getName().equals(BaseConstants.COOKIE_LANG_ID))
{
System.out.println("have cookie");
if(langid == null || langid.equals("") || !validateLang_id(langid))
langid=cookie[i].getValue();
System.out.println("inside langid: " + langid);
}
}
System.out.println("before getdefault langid: " + langid);
if(langid == null || langid.equals("") || !validateLang_id(langid)){
langid = getDefaultLangId();
}
session.setAttribute(BaseConstants.SESSION_LANG_ID, langid);
SetSessionLocale(request, langid);
return new ActionForward(ae.getPath());
}
//Validation on Get Cookie
public boolean validateLang_id(String lang_id){
boolean isValid = false;
if(lang_id.equals(BaseConstants.LANG_ENGLISH)||lang_id.equals(BaseConstants.LANG_SIMPLIFIED_CHINESE)||lang_id.equals(BaseConstants.LANG_TRADITIONAL_CHINESE))
isValid = true;
else
isValid = false;
return isValid;
}
//Get Default Lang ID
private String getDefaultLangId(){
return BaseConstants.LANG_TRADITIONAL_CHINESE;
}
public static void SetSessionLocale(HttpServletRequest request, String Lang_id){
HttpSession session = request.getSession();
if(Lang_id.equals(BaseConstants.LANG_ENGLISH))
session.setAttribute(Globals.LOCALE_KEY,Locale.ENGLISH);
else if(Lang_id.equals(BaseConstants.LANG_TRADITIONAL_CHINESE))
session.setAttribute(Globals.LOCALE_KEY,new Locale("cht","cht"));
else if(Lang_id.equals(BaseConstants.LANG_SIMPLIFIED_CHINESE))
session.setAttribute(Globals.LOCALE_KEY,new Locale("chs","chs"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -