以下链接正在运行
http://localhost:8080/MyProjectName/htmlPages/login.xhtml
这里我的项目即将在JSF中完成,但现在我需要删除" htmlPages"来自此网址。
JSF提供这样的功能吗?
答案 0 :(得分:0)
您可以使用PrettyFaces进行网址重写。
答案 1 :(得分:0)
您可以实现视图解析器过滤器。该过滤器会检查您的网址是否在网址中包含您的观看文件夹WEB-INF/htmlPages/
前缀。如果没有,则重定向到具有该前缀的网址,这样您就可以直接使用不包含htmlPages
的网址。
希望这有帮助
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
public class ViewResolverFilter implements Filter {
public static final String WEB_VIEWS_PREFIX = "/htmlPages/";
@Override
public void init(FilterConfig config) throws ServletException { }
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException, IOException {
HttpServletRequest httpRequest = (HttpServletRequest) request;
String requestURI = httpRequest.getRequestURI();
String path = requestURI.substring(httpRequest.getContextPath().length());
if (!path.startsWith(WEB_VIEWS_PREFIX)) {
String newURI = WEB_VIEWS_PREFIX + path;
request.getRequestDispatcher(newURI).forward(request, response);
} else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() { }
}
并在web.xml
:
<filter>
<filter-name>viewResolverFilter</filter-name>
<filter-class>ViewResolverFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>viewResolverFilter</filter-name>
<url-pattern>/*.xhtml</url-pattern>
</filter-mapping>