【问题标题】:tomcat can't start projectname/index.jsptomcat 无法启动 projectname/index.jsp
【发布时间】:2012-01-09 17:11:44
【问题描述】:

我遇到了与 BalusC 提供的 Run JSF project on Apache Tomcat 解决方案完全相同的问题,但不知何故对我不起作用。在我添加 jar 用于文件上传 tomahawk-1.1.10.jar、commons-fileupload-1.2.2.jar、commons-io-1.4.jar、commons-logging-1.1.1.jar、commons-el.jar 后问题开始了并在 web.xml 中设置过滤器。试图删除 jar 并使项目恢复到添加之前的状态,但仍然无法正常工作。有什么想法吗?

我使用的是 JSF 1.2 而 web.xml 是

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>iProJournal</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
    <filter>
    <filter-name>extensionsFilter</filter-name>
    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    <init-param>
        <description>Set the size limit for uploaded files.
        Format: 10 - 10 bytes
        10k - 10 KB
        10m - 10 MB
        1g - 1 GB
    </description>
        <param-name>uploadMaxFileSize</param-name>
        <param-value>100m</param-value>
    </init-param>
    <init-param>
        <description>Set the threshold size - files below this 
         limit are stored in memory, files above this limit 
         are stored on disk.
                     Format: 10 - 10 bytes
                     10k - 10 KB
                     10m - 10 MB
                     1g - 1 GB
     </description>
        <param-name>uploadThresholdSize</param-name>
        <param-value>100k</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <url-pattern>/faces/*</url-pattern>
</filter-mapping>
</web-app>

我设法让我的项目恢复到添加这些文件之前的状态,它开始工作,但我不支持导致问题的原因。这是我现在使用的 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>iProJournal</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>

【问题讨论】:

  • 您使用的是 JSF 1.x 还是 2.x?显示最小的web.xml,它仍然会重现您的问题。

标签: eclipse jsp jsf tomcat


【解决方案1】:

扩展过滤器不应映射到*.jsp 文件。它应该只映射到 JSF 请求上。不过,我建议使用不同的映射,这样您就不必担心实际要过滤的 servlet 的 URL。删除这两个过滤器映射并改用这个:

<filter-mapping>
    <filter-name>extensionsFilter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

现在每当调用FacesServlet 时都会调用它。

如果这仍然不起作用(在您将 Tomahawk 库放入 /WEB-INF/lib 之后也不起作用),那么您需要阅读服务器启动日志。

【讨论】:

    猜你喜欢
    • 2015-04-19
    • 2015-11-25
    • 2019-06-04
    • 2013-02-01
    • 2015-04-17
    • 2016-04-22
    • 1970-01-01
    相关资源
    最近更新 更多