登录前,服务器页面重定向到Filer [英] Server page redirected to Filer before Login

查看:77
本文介绍了登录前,服务器页面重定向到Filer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚部署了一个具有登录页面的应用程序。但是,使用正确密码和用户名登录时,index.xhtml会收到错误,并始终重定向到已配置的过滤器(会话超时)。重定向的原因是什么?我检查了会话是否无效,但不是这样。

I have just deployed an Application which has a login page. Upon logging in with the "right" password and "username" however, the index.xhtml gets an error and gets ALWAYS redirected to the filter( a sessions time out) that has been configured. What are the reasons for the redirection? I made a check to see if the session was invalid, but no that was not the case. Here is the web.xml(part) where the filter has been set.

错误:

Error:

    javax.faces.application.ViewExpiredException: viewId:/index.xhtml - Ansicht /index.xhtml konnte nicht wiederhergestellt werden.
        at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:205)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)
        at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
        at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
**********at **global.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:53)** --> in code snippet below*
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
        at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
        at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
        at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
        at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
        at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
        at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
        at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
        at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
        at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
        at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
        at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
        at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
        at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
        at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
        at java.lang.Thread.run(Thread.java:722)

这里是web.xml:

Here the web.xml:

<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <!--
        <param-value>Development</param-value>
        -->
        <param-value>Production</param-value>
    </context-param>
    <context-param>
        <!-- settings for file upload -->
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>30</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
        <cookie-config>
            <http-only>true</http-only>
            <secure>true</secure>
            <!-- sessionIDs are secure - look at:
                 http://www.java.net/node/703357 -->
        </cookie-config>
        <tracking-mode>COOKIE</tracking-mode>
    </session-config>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>SessionTimeoutFilter</filter-name>
        <filter-class>global.SessionTimeoutFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>SessionTimeoutFilter</filter-name>
        <url-pattern>*.xhtml</url-pattern>
    </filter-mapping>
    <error-page>
        <exception-type>javax.faces.application.ViewExpiredException</exception-type>
        <location>/timeout.xhtml</location>
    </error-page>

    <error-page> 
        <exception-type>java.lang.Throwable</exception-type> 
        <location>/error.xhtml</location> 
    </error-page>
    -->
    <security-constraint>
        <display-name>Restrict XHTML Documents</display-name>
        <web-resource-collection>
            <web-resource-name>XHTML</web-resource-name>
            <url-pattern>*.xhtml</url-pattern>
        </web-resource-collection>
    </security-constraint>

这是过滤器代码:

    public class SessionTimeoutFilter implements Filter {

        //private String timeoutPage = "timeout.xhtml";
        private String timeoutPage = "index.xhtml";


        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) 
                throws IOException, ServletException {
            if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
                HttpServletRequest httpServletRequest = (HttpServletRequest) request;
                HttpServletResponse httpServletResponse = (HttpServletResponse) response;
                // is session expire control required for this request?
                if (isSessionControlRequiredForThisResource(httpServletRequest)) {

                    // is session invalid?
                    if (isSessionInvalid(httpServletRequest)) {
                        String timeoutUrl = httpServletRequest.getContextPath() + "/" + getTimeoutPage();
                        //System.out.println("Session is invalid! redirecting to timeoutpage : "+timeoutUrl);

                        httpServletResponse.sendRedirect(timeoutUrl);
                        return;

                    }
                }
            }
   **Line 53: ERROR here-->**         filterChain.doFilter(request, response);
        }

        private boolean isSessionControlRequiredForThisResource(HttpServletRequest httpServletRequest) {
            String requestPath = httpServletRequest.getRequestURI();
            boolean controlRequired = !StringUtils.contains(requestPath, getTimeoutPage());

            return controlRequired;
        }

        private boolean isSessionInvalid(HttpServletRequest httpServletRequest) {
            boolean sessionInValid = (httpServletRequest.getRequestedSessionId() != null) 
                    && !httpServletRequest.isRequestedSessionIdValid();
            return sessionInValid;
        }

        @Override
        public void destroy() {
        }

        public String getTimeoutPage() {
            return timeoutPage;
        }

        public void setTimeoutPage(String timeoutPage) {
            this.timeoutPage = timeoutPage;
        }

    }

请指教!

推荐答案

问题是这样:

the problem is this line:

<filter-mapping>
   <filter-name>SessionTimeoutFilter</filter-name>
   <url-pattern>*.xhtml</url-pattern>
</filter-mapping>

尝试更改不包含您的登录页面或index.xhtml的url模式。

Try to change the url pattern that does not include the your login page or the index.xhtml.

这篇关于登录前,服务器页面重定向到Filer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆