JSF ViewScope: Loss QueryString with Some Initial Value in The Browser by Clicking Back

瀏覽器針對 JSF ViewScope 返回上一頁自身遇到的案例是 QueryString 會無法取得,造成參數後的初始欄位出現問題,解決方法為掛 Clear cache Filter,如下:

@@WebFilter("*.xhtml")
 public class ClearCacheFilter implements Filter {
 
     @Override
     public void init(FilterConfig filterConfig) throws ServletException {
     }
 
     @Override
     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
         HttpServletRequest req = (HttpServletRequest) request;
         HttpServletResponse res = (HttpServletResponse) response;
 
         if (!req.getRequestURI().startsWith(req.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc)
             res.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
             res.setHeader("Pragma", "no-cache"); // HTTP 1.0.
             res.setDateHeader("Expires", 0); // Proxies.
         }
         chain.doFilter(request, response);
     }
 
     @Override
     public void destroy() {
     }
 
 }

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料