session 过期时的 Ajax 请求将 <partial-response> XML 纯文本返回给浏览器

标签 ajax jsf partial-response

这就是我在页面发出 Ajax 请求并且 session 超时后在浏览器中得到的内容,我正在实现 OmniFaces FullAjaxExceptionHandler .

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<partial-response id="j_id1">
  <changes>
    <update id="javax.faces.ViewRoot">
      <![CDATA[
<html xmlns="http://www.w3.org/1999/xhtml"><head><link type="text/css" rel="stylesheet" href="/WebWorkflow/javax.faces.resource/theme.css.xhtml?ln=primefaces-smoothness" /><link type="text/css" rel="stylesheet" href="/WebWorkflow/javax.faces.resource/css/xpm2.css.xhtml" /><script type="text/javascri
]]>
      <![CDATA[
pt" src="/WebWorkflow/javax.faces.resource/jquery/jquery.js.xhtml?ln=primefaces&amp;v=5.1.13&amp;v=5.1.13"></script><script type="text/javascript" src="/WebWorkflow/javax.faces.resource/primefaces.js.xhtml?ln=primefaces&amp;v=5.1.13&amp;v=5.1.13"></script><link type="text/css" rel="stylesheet" href="/WebWorkflow/javax.faces.resource/primefaces.css.xhtml?ln=primefaces&amp;v=5.1.13&amp;v=5.1.13" /><script type="text/javascript" src="/WebWorkflow/javax.faces.resource/jquery/jquery-plugins.js.xhtml?ln=primefaces&amp;v=5.1.13&amp;v=5.1.13"></script> <meta http-equiv="cache-control" content="max-age=0" /> <meta http-equiv="cache-control" content="no-cache" /> <meta http-equiv="expires" content="0" /> <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" /> <meta http-equiv="pragma" content="no-cache" /><script type="text/javascript" src="/WebWorkflow/javax.faces.resource/jsf.js.xhtml?ln=js"></script> <title>XPM </title></head><body><span id="j_idt10"><script language="javascript" type="text/javascript"> function faceletsDebug(URL) {day = new Date();id = day.getTime();eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=800,height=600,left = 240,top = 212');"); };(function() { if (typeof jsfFaceletsDebug === 'undefined') { var jsfFaceletsDebug = false; } if (!jsfFaceletsDebug) {var faceletsOrigKeyup = document.onkeyup;document.onkeyup = function(e) { if (window.event) e = window.event; if (String.fromCharCode(e.keyCode) == 'D' & e.shiftKey & e.ctrlKey) faceletsDebug('/WebWorkflow/error/expired.xhtml?facelets.ui.DebugOutput=1429028952601'); jsfFaceletsDebug = true; if (faceletsOrigKeyup) faceletsOrigKeyup(e); }; }})();</script></span> <div id="wrapper"> <div id="header"> <form id="headerForm" name="headerForm" method="post" action="/WebWorkflow/error/expired.xhtml" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="headerForm" value="headerForm" /> <div id="headerContent"><img src="/WebWorkflow/javax.faces.resource/img/wf-logo.gif.xhtml" alt="" /><img src="/WebWorkflow/javax.faces.resource/img/header.gif.xhtml" alt="" /> <div id="welcome"> </div> </div> </form> </div> <div id="section"><div id="exceptionDialog" class="ui-dialog ui-widget ui-widget-content ui-corner-all ui-shadow ui-hidden-container"><div class="ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top"><span id="exceptionDialog_title" class="ui-dialog-title">Exception: occured!</span><a href="#" class="ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all"><span class="ui-icon ui-icon-closethick"></span></a></div><div class="ui-dialog-content ui-widget-content"> Message: <br /> StackTrace: <button id="j_idt23" name="j_idt23" type="button" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="document.location.href = document.location.href;;window.open('/WebWorkflow/error/expired.xhtml','_self')"><span class="ui-button-text ui-c">Reload!</span></button><script id="j_idt23_s" type="text/javascript">PrimeFaces.cw("Button","widget_j_idt23",{id:"j_idt23",widgetVar:"widget_j_idt23"});</script></div></div><script id="exceptionDialog_s" type="text/javascript">$(function(){PrimeFaces.cw("Dialog","exceptionDialog",{id:"exceptionDialog",widgetVar:"exceptionDialog",height:"500px"});});</script> <div id="sectionContent"> <form id="j_idt25" name="j_idt25" method="post" action="/WebWorkflow/error/expired.xhtml" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="j_idt25" value="j_idt25" /> Your session has expired. You were on page <a href="/WebWorkflow/faces/web/index.xhtml">Back to login page</a> </form> </div> </div> <div id="footer"> <div id="footerContent"><img src="/WebWorkflow/javax.faces.resource/img/stagecoachsignature.gif.xhtml" alt="" /> <ul> <li><a href="/WebWorkflow/faces/web/index.xhtml"> About My Company </a> </li> <li><a href="/WebWorkflow/faces/web/index.xhtml"> PRIVACY, Cookies, Security, Legal </a> </li> <li><a href="/WebWorkflow/faces/web/index.xhtml"> Online Access Agreement </a> </li> <li><a href="/WebWorkflow/faces/web/index.xhtml"> Contact Us </a> </li> </ul> </div> </div> </div></body> </html>
]]>
    </update>
    <update id="j_id1:javax.faces.ViewState:0">
      <![CDATA[ -1772475063786038199:-292459209620208926 ]]>
    </update>
  </changes>
</partial-response>


这是控制台中显示的错误:

FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/errorpages/expired.xhtml' will be shown.: javax.faces.application.ViewExpiredException: viewId:/login.xhtml - View /login.xhtml could not be restored.

最佳答案

我通过禁用 FullAjaxExceptionHandler 并实现我自己的 ViewExpiredExceptionHandler (ExceptionHandlerWrapper) 并在 Ajax 请求的情况下对响应进行硬编码来解决。

这篇文章中的 Douglas Junior 回答对我有用:Session timeout and ViewExpiredException handling on JSF/PrimeFaces ajax request

现在我有重定向的另一个问题,但那将是另一篇文章,谢谢大家的帮助。

关于 session 过期时的 Ajax 请求将 <partial-response> XML 纯文本返回给浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29632915/

相关文章:

javascript - 如何选择所有f :selectItems inside p:selectOneRadio with javascript in JSF?

java - 以编程方式创建一个 <ui :include src ="..."/> in backing bean

jsf - <partial-response> XML 在 WildFly 中的安全约束上进行 ajax 重定向后显示为纯文本

JavaScript只加载数据,如果有数据要加载

javascript - Jquery Ajax GET方法实现

php - 如何在 jQuery AJAX 函数中使用 'data:'?

javascript - 通过ajax对Mysql表进行排序

jsf - 为什么我的 p :progressBar not displayed, 只有数字?