gpt4 book ai didi

java - JSF2.x : page in sub folder not accessible

转载 作者:行者123 更新时间:2023-11-30 03:53:23 26 4
gpt4 key购买 nike

这是JSF2.1,JBoss 6 EAP7.1服务器项目

我想设置以下内容:

  1. 用户在浏览器中输入此 URL:http://domain.com/webApp/pathA
  2. 服务器检测到请求并注意到/pathA 位
  3. JSF 将浏览器重定向到域名.com/webApp/pathB/b.xhtml

过滤器类运行正确,由/pathA触发并运行response.sendRedirect(contextPath + "/pathB/b.xhtml");

但是浏览器遇到错误:

[地址栏]domain.com/webApp/pathB/b.xhtml

发生错误:

/b.xhtml 在ExternalContext 中未作为资源找到

com.sun.faces.context.FacesFileNotFoundException:在ExternalContext中未找到/b.xhtml作为资源 在 com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:232) 在 com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:273) 在 com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:20

如果我直接在浏览器中输入domain.com/webApp/pathB/b.xhtml,我会收到相同的错误消息

我猜问题出在 web.xml 中,但我不明白为什么......你能帮我吗?

web.xml

    <!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>


<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

<filter>
<filter-name>FormFilter</filter-name>
<filter-class>com.kit.filter.FormFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>FormFilter</filter-name>
<url-pattern>/pathA/*</url-pattern>
</filter-mapping>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>/pathB/*</url-pattern>
</servlet-mapping>
</web-app>

FormFilter.java

package com.kit.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class FormFilter implements Filter{

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

HttpServletRequest req = (HttpServletRequest) request;
//HttpSession session = req.getSession();

System.out.println("---------------------------------------------");
System.out.println("req.getRequestURI()=" + req.getRequestURI());
System.out.println("req.getContextPath()=" + req.getContextPath());
System.out.println("req.getRequestURL()=" + req.getRequestURL());
System.out.println("---------------------------------------------");

if (req.getRequestURI().contains("pathA"))
{
//HttpServletResponse res = (HttpServletResponse) response;
//res.sendRedirect("pathA/helloWorldA.xhtml");

String contextPath = ((HttpServletRequest)request).getContextPath();

System.out.println("~~~~~~~~~~~~~~ redirect to: " + contextPath + "/pathB/b.xhtml" );

((HttpServletResponse)response).sendRedirect(contextPath + "/pathB/b.xhtml");

}
else
{
chain.doFilter(request, response);
}


}

public void init(FilterConfig filterConfig) throws ServletException {

}

public void destroy() {
}


}

a.xhtml(b.xhtml 是与 a.xhtml 类似的虚拟页面)

<h:head>
<title>Secured welcome page</title>
</h:head>
<h:body>
<h:form>
<h3>Welcome AAAA</h3>
<br/>
<h:outputText value="This is an info page. Everyone has access to it!"/>
<br/>

</h:form>
</h:body>
</html>

文件结构

F:.
│ .classpath
│ .project
│ pom.xml

├─.settings
│ .jsdtscope
│ org.eclipse.jdt.core.prefs
│ org.eclipse.m2e.core.prefs
│ org.eclipse.wst.common.component
│ org.eclipse.wst.common.project.facet.core.pref
│ org.eclipse.wst.common.project.facet.core.xml
│ org.eclipse.wst.jsdt.ui.superType.container
│ org.eclipse.wst.jsdt.ui.superType.name

├─src
│ └─main
│ ├─java
│ │ └─com
│ │ └─kit
│ │ ├─controller
│ │ ├─filter
│ │ │ FormFilter.java
│ │ │
│ │ ├─model
│ │ └─util
│ │ DigitCaptcha.java
│ │ RequestFormStage.java
│ │
│ ├─resources
│ └─webapp
│ │ helloWorld.xhtml
│ │ index.xhtml
│ │ template.xhtml
│ │
│ ├─pathA
│ │ a.xhtml
│ │
│ ├─pathB
│ │ b.xhtml
│ │
│ └─WEB-INF
│ │ .faces-config.xml.jsfdia
│ │ beans.xml
│ │ faces-config.xml
│ │ web.xml
│ │
│ └─lib
└─target
├─classes
│ └─com
│ └─kit
│ ├─filter
│ │ FormFilter.class
│ │
│ └─util
│ DigitCaptcha.class
│ RequestFormStage.class

├─generated-sources
│ └─annotations
├─maven-archiver
│ pom.properties

└─webApp
│ helloWorld.xhtml
│ index.xhtml
│ template.xhtml

├─META-INF
├─pathA
│ a.xhtml

├─pathB
│ b.xhtml

└─WEB-INF
│ .faces-config.xml.jsfdia
│ beans.xml
│ faces-config.xml
│ web.xml

├─classes
│ └─com
│ └─kit
│ ├─filter
│ │ FormFilter.class
│ │
│ └─util
│ DigitCaptcha.class
│ RequestFormStage.class

└─lib
jboss-logging-3.1.3.GA.jar
primefaces-4.0.jar

最佳答案

/pathB/* 行导致了问题,删除该行后,过滤器的重定向工作正常

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

关于java - JSF2.x : page in sub folder not accessible,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23833059/

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