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

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

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

    Bryan

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      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. 閱讀(570) 評論(0)  編輯  收藏 所屬分類: Java
    主站蜘蛛池模板: 亚洲AV无码久久精品蜜桃| 精品国产呦系列在线观看免费| A级毛片内射免费视频| 亚洲欧美国产欧美色欲| www.亚洲一区| 久久99国产综合精品免费| 亚洲成a人片在线观看天堂无码| 中文字幕亚洲一区二区va在线| 久久爰www免费人成| 亚洲色大成网站www永久男同 | a级毛片免费完整视频| 亚洲国产成人精品电影| 国产裸体美女永久免费无遮挡| 久久亚洲成a人片| 日韩中文无码有码免费视频 | 久久青草免费91线频观看站街| 亚洲另类小说图片| 国产精品亚洲综合一区| 波多野结衣中文字幕免费视频| 成人特级毛片69免费观看| 亚洲国产精品久久久久秋霞影院| 午夜亚洲av永久无码精品| 91高清免费国产自产拍2021| 阿v免费在线观看| 亚洲午夜成激人情在线影院| 国产亚洲精品无码专区| 一本无码人妻在中文字幕免费 | 亚洲综合久久综合激情久久| 免费在线不卡视频| 97视频免费在线| 国产一二三四区乱码免费| 亚洲成av人片天堂网无码】| 精品亚洲国产成AV人片传媒| 亚洲人成网站在线观看青青| 最近最好的中文字幕2019免费 | 亚洲成在人线中文字幕| 亚洲乱码无码永久不卡在线| 国产麻豆一精品一AV一免费| 粉色视频成年免费人15次| 亚洲性无码一区二区三区| 亚洲黄色片免费看|