我正在发布解决方案,这可能会对其他面临相同问题的人有所帮助。我要做的就是实现自己的
javax.faces.application.ViewHandler并将其注册到
faces-config.xml:
public class CustomViewHandler extends ViewHandlerWrapper { private ViewHandler wrappped; public CustomViewHandler(ViewHandler wrappped) { super(); this.wrappped = wrappped; } @Override public ViewHandler getWrapped() { return wrappped; } @Override public String getActionURL(FacesContext context, String viewId) { String url = super.getActionURL(context, viewId); return removeContextPath(context, url); } @Override public String getRedirectURL(FacesContext context, String viewId, Map<String, List<String>> parameters, boolean includeViewParams) { String url = super.getRedirectURL(context, viewId, parameters, includeViewParams); return removeContextPath(context, url); } @Override public String getResourceURL(FacesContext context, String path) { String url = super.getResourceURL(context, path); return removeContextPath(context, url); } private String removeContextPath(FacesContext context, String url) { ServletContext servletContext = (ServletContext) context.getExternalContext().getContext(); String contextPath = servletContext.getContextPath(); if("".equals(contextPath)) return url; // root context path, nothing to remove return url.startsWith(contextPath) ? url.substring(contextPath.length()) : url; }}
faces-config.xml:
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"> <application> <view-handler>test.CustomViewHandler</view-handler> </application></faces-config>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)