struts2入门(-)

struts2入门之环境搭建篇

本例使用 IDEA maven构建struts2入门程序,步骤如下:

  1. 新建maven项目,注意不要选取maven骨架。待会自己导入需要的模块即可
    struts2入门(-)struts2入门(-)
  2. 添加web模块:
    struts2入门(-)需要注意的是:maven默认web resources的路径为 …/项目名称/src/main/webapp,生成的确实…/项目名称/web,后续需要在pom.xml中指定web.xml位置(配置如下),否则会报错:大意是没有配置web.xml,这里是我之前做maven父子模块遇到的问题,其中maven-war-plugin插件还有其他用处,自行百度。
<!-- 配置web.xml文件的配置 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <!-- 指定web.xml的路径  -->
                    <webXml>web\WEB-INF\web.xml</webXml>
                    <!-- 指定jsp、js、css的路径 -->
                    <warSourceDirectory>web</warSourceDirectory>
                </configuration>
            </plugin>
  1. 添加stuts2依赖:
<dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.3.24</version>
</dependency>         
  1. 配置tomcat,使用maven tomat插件。
	<plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>8080</port>
                    <path>/demo</path>
                </configuration>
         </plugin>

struts2入门(-)
maven 命令运行tomcat如下:

clean tomcat7:run