我正在使用spring 3.2.2,hibernate 4.2.2和JSF 2.1(mojora)和RichFaces 4.3.2运行应用程序
我的配置很好用。我可以通过.xhtml,.jsf,.jsp访问页面但是......
当您尝试访问不存在的页面时,问题出现在显示屏上(例如未创建的blabla.xhtml示例)。如何处理错误?
谢谢你的帮助。
这是错误,这将导致无限递归:
ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
这是我的web.xml:
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF Mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
<url-pattern>*.xhtml</url-pattern>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>
<!-- 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>
<!-- Faces ConfigPath Context -->
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>classpath:webConfiguration/faces-config.xml</param-value>
</context-param>
<!-- Add Spring Context -->
<context-param>
<param-name> contextConfigLocation </param-name>
<param-value>classpath:webConfiguration/applicationContext.xml</param-value>
</context-param>
<!-- Apache EL Faces Context -->
<context-param>
<param-name>com.sun.faces.expressionFactory</param-name>
<param-value>com.sun.el.ExpressionFactoryImpl</param-value>
</context-param>
<!-- Richfaces Skin Context -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>laguna</param-value>
</context-param>
<!-- Add Support for Spring -->
<listener><listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class></listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class></listener>
答案 0 :(得分:0)
对于不存在的页面,您应该收到错误状态代码404.您可以通过在web.xml
<error-page>
<error-code>404</error-code>
<location>/error.xhtml</location>
</error-page>
答案 1 :(得分:0)
这很容易。在根控制器中设置此Mapping函数,但importat是您的子控制器没有任何带* character
的映射根控制器功能示例:
@RequestMapping(value={"/*", "/**"})
public String pageNotFound() {
return "app/pagenotfound";
}
子链接或子映射控制器的映射示例
@RequestMapping(value={"/something", "/something/"})
如果你像这样decaler子映射控制器:
@RequestMapping(value={"/something", "/something/*"})
然后root控制器将省略该控制器的pageNotFound映射功能。