Struts2 IDEA项目开发
1. pom.xml
注意 打包方式<packaging>war</packaging>
访问路径<artifactId>struts-sample</artifactId>
<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>org.apache.struts</groupId>
<artifactId>struts-sample</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>Struts 2 Examples</name>
<description>
This is the parent pom for the Struts 2 examples that
go with the Struts 2 Getting Started series of tutorials.
</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<struts2.version>2.5.17</struts2.version>
<log4j2.version>2.9.1</log4j2.version>
<jetty-plugin.version>9.4.11.v20180605</jetty-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>${struts2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j2.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-plugin.version}</version>
<configuration>
<webApp>
<contextPath>/${project.artifactId}</contextPath>
</webApp>
<stopKey>CTRL+C</stopKey>
<stopPort>8089</stopPort>
<scanIntervalSeconds>10</scanIntervalSeconds>
<scanTargets>
<scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
</scanTargets>
</configuration>
</plugin>
</plugins>
</build>
</project>
2. web.xml
注意struts2版本,org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 是2.5版本,和2.3版本不一致
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.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>
3. struts.xml
http://localhost:8080/struts-sample/test/index
访问路径=<artifactId>struts-sample</artifactId> + <package name="test" > + <action name="index">
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="test" extends="struts-default">
<!-- If no class attribute is specified the framework will assume success and
render the result index.jsp -->
<!-- If no name value for the result node is specified the success value is the default -->
<action name="index">
<result>/index.jsp</result>
</action>
<!-- If the URL is hello.action then call the execute method of class HelloWorldAction.
If the result returned by the execute method is success render the HelloWorld.jsp -->
<action name="hello" class="Register" method="execute">
<result name="success">/Helloworld.jsp</result>
</action>
</package>
</struts>
启动日志
启动 maven工具 jetty:run
[INFO] — jetty-maven-plugin:9.4.11.v20180605:run (default-cli) @ struts_demo —
[INFO] Logging initialized @3383ms to org.eclipse.jetty.util.log.Slf4jLog
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] nonBlocking:false
[INFO] Classes = /Users/Rukawa/Projects/struts_demo/target/classes
[INFO] Configuring Jetty for project: struts_demo
[INFO] Context path = /struts_demo
[INFO] Tmp directory = /Users/Rukawa/Projects/struts_demo/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:///Users/Rukawa/Projects/struts_demo/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /Users/Rukawa/Projects/struts_demo/src/main/webapp
[INFO] jetty-9.4.11.v20180605; built: 2018-06-05T18:24:03.829Z; git: d5fc0523cfa96bfebfbda19606cad384d772f04c; jvm 1.8.0_65-b17
[WARNING] Unknown asm implementation version, assuming version 393216
[INFO] Scanning elapsed time=439ms
[INFO] DefaultSessionIdManager workerName=node0
[INFO] No SessionScavenger set, using defaults
[INFO] node0 Scavenging every 660000ms
[INFO] Started o.e.j.m.p.JettyWebAppContext@35ff8fc9{/struts_demo,file:///Users/Rukawa/Projects/struts_demo/src/main/webapp/,AVAILABLE}{file:///Users/Rukawa/Projects/struts_demo/src/main/webapp/}
[INFO] Started ServerConnector@508b194b{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[INFO] Started @6553ms
[INFO] Started Jetty Server
[INFO] Using Non-Native Java sun.nio.fs.PollingWatchService
[WARNING] Quiet Time is too low for non-native WatchService [sun.nio.fs.PollingWatchService]: 1000 < 5000 ms (defaulting to 5000 ms)
2019-09-24 22:23:13 [qtp1640458320-17] WARN SecurityMemberAccess:133 - The use of the default (unnamed) package is discouraged!