问题描述
- struts登录拦截器问题
-
问题:登录之后跳转到一个jsp页面,该页面上通过跳转时被登录拦截器拦截。
我想问的是,明明已经登录之后再跳转的,为什么会被登录拦截器拦截呢?刚开始接触这一块,不是很懂,希望能尽快得到大神们的帮助,谢谢谢谢谢谢!!
解决方案
struts实现拦截器的问题
STRUTS2 登录拦截器
struts2登录拦截器代码实例
解决方案二:
what are you 说啥累?不粘代码怎么知道哪里错了?
解决方案三:
拦截器在action动作的前后都会拦截的。估计你的拦截器在invoke方法之后还有其他行为吧
解决方案四:
说明你的拦截器没有判断是否已登录 已登录应该执行 return invoker.invoke();
解决方案五:
Filter代码:
public class UserAuthenticationFilter implements javax.servlet.Filter {
protected FilterConfig filterConfig = null;
private String redirectURL = null;
private List notCheckURLList = new ArrayList();
private String sessionKey = null;
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) servletResponse;
HttpSession session = request.getSession();
if (sessionKey == null) {
filterChain.doFilter(request, response);
return;
}
if ((!checkRequestURIIntNotFilterList(request))
&& session.getAttribute(sessionKey) == null) {
response.sendRedirect(request.getContextPath() + redirectURL);
return;
}
filterChain.doFilter(servletRequest, servletResponse);
}
public void destroy() {
notCheckURLList.clear();
}
private boolean checkRequestURIIntNotFilterList(HttpServletRequest request) {
String uri = request.getServletPath()
+ (request.getPathInfo() == null ? "" : request.getPathInfo());
return notCheckURLList.contains(uri);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
redirectURL = filterConfig.getInitParameter("redirectURL");
sessionKey = filterConfig.getInitParameter("checkSessionKey");
String notCheckURLListStr = filterConfig.getInitParameter("notCheckURLList");
if (notCheckURLListStr != null) {
StringTokenizer st = new StringTokenizer(notCheckURLListStr, ";");
notCheckURLList.clear();
while (st.hasMoreTokens()) {
notCheckURLList.add(st.nextToken());
}
}
}
}
解决方案六:
struts.xml部分配置:
<action name="login" class="com.action.LoginAction" method="loginAction">
<result name="ordinaryUser" type="chain">getProjectHomePage</result>
</action>
<action name="getProjectHomePage" class="com.action.OnloadProjectHomePage" method="onloadProjectHomePage">
<result name="success">/homepage.jsp</result>(注:我把这里的homepage.jsp改成了另外一个页面main.jsp)
<result name="error">/error.jsp</result>
解决方案七:
web.xml部分配置:
UserAuthenticationFilter
com.filters.UserAuthenticationFilter
checkSessionKey
loginUser
redirectURL
/loginTimeout.jsp
notCheckURLList
/error.jsp;/notFound.jsp;/login.jsp;/loginTimeout.jsp;/web/login;/web/index;/web/loginOut
解决方案八:
web.xml部分配置:
UserAuthenticationFilter
com.filters.UserAuthenticationFilter
checkSessionKey
loginUser
redirectURL
/loginTimeout.jsp
notCheckURLList
/error.jsp;/notFound.jsp;/login.jsp;/loginTimeout.jsp;/web/login;/web/index;/web/loginOut
解决方案九:
web.xml部分配置:
<filter>
<filter-name>UserAuthenticationFilter</filter-name>
<filter-class>com.filters.UserAuthenticationFilter</filter-class>
<init-param>
<param-name>checkSessionKey</param-name>
<param-value>loginUser</param-value>
</init-param>
<init-param>
<param-name>redirectURL</param-name>
<param-value>/loginTimeout.jsp</param-value>
</init-param>
<init-param>
<param-name>notCheckURLList</param-name>
<param-value>/error.jsp;/notFound.jsp;/login.jsp;/loginTimeout.jsp;/web/login;/web/index;/web/loginOut</param-value>
</init-param>
</filter>
解决方案十:
main.jsp页面跳转部分:
<a href="modifyUser.jsp">个人信息修改</a>(注:此处modifUser.jsp为原项目的页面,main.jsp为本人添加的新页面)
问题:以上修改本意是登录成功之后跳转到main页面,然后通过点击 个人信息修改 希望能够跳转到个人信息修改页面,但是在跳转的实际情况中要求重新登录,希望大神们指点迷津