Tomcat 从META-INF/context.xml获取web应用程序上下文路径,以生成导航结果
我有一个在Tomcat8上运行的primefaces web应用程序。在Tomcat 从META-INF/context.xml获取web应用程序上下文路径,以生成导航结果,tomcat,jsf,primefaces,contextpath,Tomcat,Jsf,Primefaces,Contextpath,我有一个在Tomcat8上运行的primefaces web应用程序。在META-INF/context.xml中,我定义了以下内容: <?xml version="1.0" encoding="UTF-8"?> <Context antiJARLocking="true" path="/syslac"/> 在我的视图xhtml页面中,我有一段代码,其中p:commandButton有一个oncomplete标记,它将执行handleLoginRequest函数 &
META-INF/context.xml
中,我定义了以下内容:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/syslac"/>
在我的视图xhtml页面中,我有一段代码,其中p:commandButton有一个oncomplete标记,它将执行handleLoginRequest函数
<h:form>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Usuario:" />
<p:inputText value="#{loginBean.usuarioVendedor.usuarioSistema}" id="username" required="true" label="username" />
<h:outputLabel for="password" value="Contrasena:" />
<h:inputSecret value="#{loginBean.usuarioVendedor.clave}" id="password" required="true" label="password" />
<f:facet name="footer">
<p:commandButton value="Ingresar" update=":growl" actionListener="#{loginBean.loguearse}" oncomplete="handleLoginRequest(xhr, status, args)" />
</f:facet>
</h:panelGrid>
</h:form>
剧本:
<script type="text/javascript">function handleLoginRequest(xhr, status, args)
{
if (args.validationFailed || !args.loggedIn) {
jQuery('#dialog').effect("shake", {times: 2}, 100);
} else {
dlg.hide();
jQuery('#loginLink').fadeOut();
window.location = args.view;
}
}
</script>
函数handleLoginRequest(xhr、状态、参数)
{
if(args.validationFailed | | |!args.loggedIn){
jQuery('#dialog').effect(“shake”,{times:2},100);
}否则{
dlg.hide();
jQuery(“#loginLink”).fadeOut();
window.location=args.view;
}
}
但是我无法通过logginBean从META-INF/context.xml中检索上下文路径,这样我就可以发送视图arg供window使用。导航中的位置:
/syslac/page.xhtml
,其中syslac是应用程序的上下文路径。上下文路径位于可用的备份bean中
例如,你可以这样做:
String loginURI = contextPath + "/login.xhtml";
// ...
<h:outputScript>
// ...
window.location = "#{request.contextPath}" + args.view;
</h:outputScript>
注意,当作为JSF导航结果使用时,这是完全不必要的。有关正确的方法,请参阅底部的第二个“请参阅”链接
上下文路径在EL by中可用
例如,你可以这样做:
String loginURI = contextPath + "/login.xhtml";
// ...
<h:outputScript>
// ...
window.location = "#{request.contextPath}" + args.view;
</h:outputScript>
另见:
<html lang="en" data-baseuri="#{request.contextPath}">
window.location = document.documentElement.dataset.baseuri + args.view;