添加Struts2过滤器会导致空白页面

时间:2014-01-12 20:54:08

标签: java jsp maven tomcat struts2

我正在尝试使用基本的Struts2应用程序(使用tomcat,使用maven构建)启动并运行。 Tomcat和Maven都正常工作;页面是正常提供的,直到我将一些Struts过滤器添加到我的web.xml(位于src / main / webapp / WEB-INF)。这是我的web.xml的代码:

<?xml version="1.0" encoding="UTF-8" ?>
<web-app>

    <display-name>app</display-name>
    <description>tagline</description>

    <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>struts2</filter-name>
       <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>  

此外,这是我的struts.xml的代码(位于src / main / resources:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />
    <package name="app" extends="struts-default">
        <action name="index">
            <result>/index.jsp</result>
        </action>
    </package>
</struts>

我的catalina.log有以下错误消息:

12-Jan-2014 15:33:20.256 SEVERE [localhost-startStop-16] org.apache.catalina.core.StandardContext.startInternal Error filterStart
12-Jan-2014 15:33:20.256 SEVERE [localhost-startStop-16] org.apache.catalina.core.StandardContext.startInternal Context [/app] startup failed due to previous errors

我刚刚注意到catalina.log中存在的另一个问题,它只在启动tomcat时显示:

13-Jan-2014 20:19:57.465 SEVERE [main] org.apache.catalina.core.AprLifecycleListener.init An incompatible version 1.1.27 of the APR based Apache Tomcat Native library is installed, while Tomcat requires version 1.1.29

非常奇怪的是我的apache-tomcat-ver / bin中的tomcat-native.tar.gz是版本1.1.29。

此外,我的localhost.log有一堆错误:

13-Jan-2014 20:20:04.780 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.filterStart Exception starting filter struts2
 Unable to load configuration. - bean - jar:file:/usr/local/apache-tomcat/apache-tomcat-8.0.0-RC10/webapps/symIOsis/WEB-INF/lib/struts2-portlet-plugin-2.3.16.jar!/struts-plugin.xml:31:133
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:501)
    at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:74)
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:57)
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
    at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4646)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5274)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:699)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1763)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
Caused by: Unable to load configuration. - bean - jar:file:/usr/local/apache-tomcat/apache-tomcat-8.0.0-RC10/webapps/symIOsis/WEB-INF/lib/struts2-portlet-plugin-2.3.16.jar!/struts-plugin.xml:31:133
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:70)
    at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:445)
    at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:489)
    ... 18 more
Caused by: Unable to load bean: type:org.apache.struts2.components.UrlRenderer class:org.apache.struts2.components.PortletUrlRenderer - bean - jar:file:/usr/local/apache-tomcat/apache-tomcat-8.0.0-RC10/webapps/symIOsis/WEB-INF/lib/struts2-portlet-plugin-2.3.16.jar!/struts-plugin.xml:31:133
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:245)
    at org.apache.struts2.config.StrutsXmlConfigurationProvider.register(StrutsXmlConfigurationProvider.java:102)
    at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:234)
    at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:67)
    ... 20 more
Caused by: java.lang.NoClassDefFoundError: javax/portlet/PortletMode
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2493)
    at java.lang.Class.getDeclaredConstructors(Class.java:1901)
    at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.register(XmlConfigurationProvider.java:235)
    ... 23 more
Caused by: java.lang.ClassNotFoundException: javax.portlet.PortletMode
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1286)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1128)
        ... 27 more

对我而言,这看起来像是依赖问题,但是该位置存在struts2-portlet-plugin-2.3.16.java。有谁知道如何解决这个问题?

编辑:我还将struts2-portlet-plugin添加为maven依赖项,希望它能解决问题。无济于事,同样的错误仍在出现。

此外,这是请求的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.company.webapp</groupId>
  <artifactId>webapp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>webapp</name>
  <url>http://maven.apache.org</url>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <build>
        <finalName>app</finalName>
  </build>

  <dependencies>
     <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
       </dependency>
    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.16</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-portlet-plugin</artifactId>
      <version>2.3.16</version>
    </dependency>
  </dependencies>
</project>

1 个答案:

答案 0 :(得分:1)

经过多次头痛和大量的圈子后,我似乎已经找到了问题。显然,在使用maven构建时,我不需要将.jars从分布式struts-ver / lib复制到我的WEB-INF / lib文件夹中。它总是很简单,嗯?