<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Bryan

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      37 Posts :: 3 Stories :: 24 Comments :: 0 Trackbacks
    I am maintaining a tool formerly developed by an Indian for PDM system which use the dsl format file as input to generate one text file and one excel file.The text/excel file path stored in the session and appear on the result page for downloading , the tool always shows empty page when session is time out(the path is lost in the session), end users always complain about it and donot know what happened.I take charge of this tool and add one java filter to direct to session time-out page when the session is time out.

    It's easy to implement it,you can create one backing bean and use the command link action attribute to invoke the file download.you can refer to the site:http://wiki.apache.org/myfaces/Sending_Files.In this way,you can only popup a excel download window.
    <h:commandLink action="#{downloadFileBean.downloadFile}">
        
    <h:outputText value="#{apnStocklist.excelfile}"></h:outputText>
    </h:commandLink>

    But this tool is a little bit different and that's why I wrote this passage I donot know why the Indian implement it this way.This web application executes the logic and generate two Myfaces h:command links (text link and excel link) on one result page and then use java servlet to download the files(open in new window). The following is the link appearing on the result page(Myfaces jsp code)
    <h:commandLink onclick="openWin('/servlet/DownloadFileServlet');">
       
    <h:outputText value="#{apnStocklist.txtfile}"></h:outputText>
    </h:commandLink>


    I add one sessionExpired(sessionExpired.jsp) page and if the session time out , the result page and the newly servlet opening window both will direct to session expired page.
    public void doFilter(ServletRequest servletRequest,
            ServletResponse servletResponse, FilterChain filterChain)
            
    throws IOException, ServletException {
        HttpServletRequest request 
    = (HttpServletRequest) servletRequest;
        HttpServletResponse response 
    = (HttpServletResponse) servletResponse;
        
    boolean sessionInvalid = (null != request.getRequestedSessionId())
            
    && !request.isRequestedSessionIdValid();
        HttpSession session 
    = request.getSession();
        System.out.println(
    "-----------------------------" + request.getRequestURI() + "----------------------------");    
        System.out.println(
    "session is new:---" + session.isNew());
        System.out.println(
    "request session id:---" + request.getRequestedSessionId() + " session id:---" + session.getId());
        
    if (sessionInvalid) {
            response.sendRedirect(request.getContextPath() 
    + "/jsp/"
                
    + SESSION_TIME_OUT_PAGE);
            
    return;
        }

        filterChain.doFilter(servletRequest, servletResponse);
        }


     I check the most of the web sites, including the spring security, they always use the following code to check whether session is time out or not.
    boolean sessionInvalid = (null != request.getRequestedSessionId())&& !request.isRequestedSessionIdValid();
    But for this tool, since the downloading is opened via new window(Multiple requests), It behaves differently for IE6 and firedox. As the Myfaces ManagedBean is in request scope,clicking the link will call the servlet code as well as ManagedBean constructor code(initialize the bean instance) .For Firefox,It 's working fine, both the window direct to session time out page ,But for the IE6 ,only the servlet window directs, the result page doesnot. After debuging the application, I found the application call order is not the same,I donot know why?

    when the session time out
    IE6: the servlet code will call first, and then direct to session expired page, then the result page (ManagedBean code) called.
    Firefox : the servlet code will call first,the result page,session expired page,session expired page(both  direct to)

    IE6: 8F1F773477460348836FB47C440FBD6E is the session Id before session time out and when the session time out, the servlet will create one session and then request.getRequestSessionId changed
    -----------------------------DownloadFileServlet----------------------------
    session is new:---true
    request session id:---8F1F773477460348836FB47C440FBD6E session id:---DC720FACE7367E81680542290EF6AE9A
    ----------------------------sessionExpired.faces----------------------------
    session is new:---false
    request session id:---DC720FACE7367E81680542290EF6AE9A session id:---DC720FACE7367E81680542290EF6AE9A
    -----------------------------results.faces----------------------------
    session is new:---false
    request session id:---DC720FACE7367E81680542290EF6AE9A session id:---DC720FACE7367E81680542290EF6AE9A

    Firefox
    -----------------------------DownloadFileServlet----------------------------
    session is new:---true
    request session id:---2EEFE6AF9DE431CDB555D86A7C4C77CE session id:---CC5A8338993E0A4F2CA9B2AB7CECFA56
    -----------------------------results.faces----------------------------
    session is new:---true
    request session id:---2EEFE6AF9DE431CDB555D86A7C4C77CE session id:---E08C640D9EE6815CCBEA8A4A1F06573B
    -----------------------------sessionExpired.faces----------------------------
    session is new:---false
    request session id:---CC5A8338993E0A4F2CA9B2AB7CECFA56 session id:---CC5A8338993E0A4F2CA9B2AB7CECFA56
    -----------------------------sessionExpired.faces----------------------------
    session is new:---false
    request session id:---E08C640D9EE6815CCBEA8A4A1F06573B session id:---E08C640D9EE6815CCBEA8A4A1F06573B

    Finally I have two ways to solve it.

    1.donot use pure servlet to download files ,just use managed bean to download files instead(without popup window)
    2.use session.getAttribute("User") == null to check whether the session is time out or not.

    Meanwhile, we often encounter the following exceptions about session.That's because before we call the session.setAttribute("User"), the session is already invalid.when encountering this exception, we have to find what has caused the application session invalid before we use session to set attributes.
    Caused by: java.lang.IllegalStateException: setAttribute: Session already invalidated
            at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:
    1289)
            at org.apache.catalina.session.StandardSession.setAttribute(StandardSession.java:
    1254)
            at org.apache.catalina.session.StandardSessionFacade.setAttribute(StandardSessionFacade.java:
    130)

    Ref:
    http://techieexchange.wordpress.com/2008/02/21/jsf-session-expired-timeout-solution/
    posted on 2011-09-29 16:13 Life is no respector of any genius. 閱讀(577) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲国产精品综合久久2007| 免费无码午夜福利片69| 久久美女网站免费| 亚洲日本韩国在线| 日本中文字幕免费看| 国产伦精品一区二区三区免费下载| 亚洲依依成人亚洲社区| 成人免费在线观看网站| 亚洲综合一区无码精品| 国产美女无遮挡免费视频网站 | 亚洲天堂一区二区三区四区| 久久久久久夜精品精品免费啦| 亚洲视频小说图片| 114一级毛片免费| 亚洲色成人网站WWW永久四虎| 色www永久免费视频| 免费国产va视频永久在线观看| 国产日韩成人亚洲丁香婷婷| 久久一区二区三区免费| 亚洲AV无码久久精品成人| 18禁止看的免费污网站| 亚洲日本成本人观看| 亚洲精品国产精品国自产观看 | 亚洲中文字幕久久久一区| 成全视频在线观看免费高清动漫视频下载 | 亚洲无限乱码一二三四区| 亚洲精品国产免费| 亚洲精品国产av成拍色拍| 亚洲精品国产日韩无码AV永久免费网 | 又爽又高潮的BB视频免费看| 中国人免费观看高清在线观看二区| 久久久久久久久亚洲| 成人A级毛片免费观看AV网站| 美女裸体无遮挡免费视频网站| 亚洲无av在线中文字幕| 亚洲免费观看网站| 美女视频黄频a免费大全视频| 亚洲AV无码乱码国产麻豆| 好男人看视频免费2019中文| 97在线免费观看视频| 亚洲已满18点击进入在线观看|