gpt4 book ai didi

javascript - window.location.href 不渲染 Facelets 页面,返回原始源代码

转载 作者:行者123 更新时间:2023-11-28 09:24:59 27 4
gpt4 key购买 nike

我在从 Javascript 加载 Facelets 页面时遇到问题。我正在使用 Netbeans 7.2、Glassfish 3.1.2 和 Java EE 6。

我做了一个简单的测试页面:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<script type="text/javascript">
window.location.href = "index.xhtml";
</script>
<title>winq match!</title>
</h:head>
<h:body>
<h1>WING MATCH!!</h1>
<h:form>
<h:commandButton id="Next" value="weiter" action="index"/>
</h:form>
</h:body>

应使用 window.location.href 加载的 index.xhtml 页面是:

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="TestTestTestTestTest"/>
msg <h:inputText id="ema" value="#{testBean.inputValue}" maxlength="1" />
<h:commandButton id="but" value="Submit" action="index"/>
</h:form>
</h:body>

页面已加载但未解析,因此浏览器不会解释 h: 标记。在网上搜索后,似乎我是唯一一个遇到这样问题的人。也许我误解了 JSF 的某些方面。我希望得到一些建议。

最佳答案

您需要确保请求 URL 与 Web 应用程序的 web.xml 中定义的 FacesServlet 的 URL 模式匹配。即它负责执行所有 JSF/Facelets 工作。

例如,如果您已将其映射到 *.jsf 上,那么您应该完全按照该 URL 模式打开页面,以便正确调用 FacesServlet将找到 index.xhtml 文件并执行所有必要的操作。

window.location.href = "index.jsf";

或者,您也可以将 FacesServlet 的 URL 模式更改为 *.xhtml。这样您就无需担心虚拟 URL。

另请参阅:

关于javascript - window.location.href 不渲染 Facelets 页面,返回原始源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14511982/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com