1

我试图让我的 Struts2 项目与 Tiles 和 Tomcat 服务器一起运行,但我就是无法让它工作。

我已经查看了两者的文档,我认为我做得对。这是我的文件:web.xml

<display-name>Struts2_Application</display-name>
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>

<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>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

struts.xml

    <?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>
   <package name="default" extends="struts-default">
      <result-types>
         <result-type name="tiles" 
         class="org.apache.struts2.views.tiles.TilesResult" />
      </result-types>


      <action name="*Menu" method="{1}" 
         class="com.greensun.struts2.tiles.action.MenuAction">
         <result name="tiger" type="tiles">tiger</result>
         <result name="lion" type="tiles">lion</result>
      </action>

   </package>
</struts>

MenuAction.java

public class MenuAction extends ActionSupport {

/**
 * 
 */
/*private static final long serialVersionUID = 1L;
@Override
public String execute() throws Exception {
    // TODO Auto-generated method stub
    return "tiger";
}*/

public String tiger() { return "tiger"; }
public String lion() { return "lion"; }
  }

当我尝试运行该项目时,我收到此错误:

org.apache.catalina.core.StandardContext listenerStart 严重:类 org.apache.struts2.tiles.StrutsTilesListener 异常将上下文初始化事件发送到 org.apache.tiles.context.ChainedTilesContextFactory.createApplicationContext(ChainedTilesContextFactory 的 java.lang.NullPointerException 的侦听器实例.java:107) 在 org.apache.struts2.tiles.StrutsTilesContainerFactory.initializeContainer(StrutsTilesContainerFactory.java:68) 在 org.apache.struts2.tiles.StrutsTilesContainerFactory.initializeContainer(StrutsTilesContainerFactory.java:68) 在 org.apache.struts2.tiles.StrutsTilesContainerFactory$StrutsTilesContextFactory.createApplicationContext(StrutsTilesContainerFactory.java:98)。 org.apache.tiles.factory.TilesContainerFactory.createContainer(TilesContainerFactory.java:164) 的 org.apache.tiles.listener 中的 tiles.factory.TilesContainerFactory.createTilesContainer(TilesContainerFactory.java:199)。TilesListener.createContainer(TilesListener.java:91) at org.apache.struts2.tiles.StrutsTilesListener.createContainer(StrutsTilesListener.java:66) at org.apache.tiles.listener.TilesListener.contextInitialized(TilesListener.java:58) at org .apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 在 org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase .java:150) 在 org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901) 在 org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877) 在 org.apache.catalina。 core.StandardHost.addChild(StandardHost.java:633) 在 org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656) 在 org.apache.catalina.startup。HostConfig$DeployDescriptor.run(HostConfig.java:1635) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor .runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

我确定我在做一些非常愚蠢的事情,但我自己看不到。任何人?

4

0 回答 0