rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 程序开发 » JavaEE

Struts2 with Maven

http://struts.apache.org/2.1.8.1/docs/struts-2-maven-archetypes.html

Set the tools.jar dependence in your pom.xml

<project ...>
...
<!-- tools.jar dependecy -->
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.6.0_07/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
...
</dependencies>
</project>

9- Add struts2

<project ...>
...
<dependencies>
...
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11.2</version>
</dependency>
</dependencies>
</project>

10- The finale pom.xml will look like

<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.agafix</groupId>
<artifactId>tuto_hello</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>tuto_hello Maven Webapp</name>
<url>http://maven.apache.org</url>
<!-- tools.jar dependecy -->
<profiles>
<profile>
<id>default-tools.jar</id>
<activation>
<property>
<name>java.vendor</name>
<value>Sun Microsystems Inc.</value>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.5.0</version>
<scope>system</scope>
<systemPath>C:/Program Files/Java/jdk1.6.0_07/lib/tools.jar</systemPath>
</dependency>
</dependencies>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11.2</version>
</dependency>
</dependencies>
<build>
<finalName>tuto_hello</finalName>
</build>
</project>
struts2 welcome-file-list 设置的路径不能是Action地址

在welcome-file-list 设置的路径是要去web应用根目录下去找,比如,设置了<welcome-file>index.jsp</welcome-file>,那么,首先不输入具体访问文件的时候,它就会去WEB应用根目录去找index.jsp文件,如果没有这个文件的话,自然页面不会有任何显示,所以,直接写这个action地址是不可行的,因为,建不了这样一个action的文件。但是<welcome-file-list> 里可以配置servlet 没法配置action。
在 tomcat 中配置的 <welcom-file> 是基于servlet 的struts2 的运行机制却是filter .

解决办法,设置index.jsp等,在这个里面通过url跳转或struts2的action标签跳转到你的action的地址就可以了,

web.xml中这样配置 
<welcome-file-list> 
  <welcome-file>index.jsp</welcome-file> 
</welcome-file-list>

然后在index.jsp中使用Struts2的标签 
<s:action name="getDataInfo" executeResult="true"></s:action>

这个标签会执行这个action,然后返回结果页面.

顶一下
(0)
踩一下
(0)