Maven构建Struts2实例
2017-12-28 15:56
309 查看
怎么构建Maven项目就不多说了。很简单,就直接贴代码了。IntelliJ IDEA 创建Maven 工程
项目目录:
源码GitHub地址。
项目目录:
pom.xml
可以用Maven的Tomcat7插件,也可以用自己本地的Tomcat。本地的Tomcat在Run>>Edit Configurations中配置。<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>com.mistra.ms</groupId> <artifactId>MistraRMStruts2</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>MistraRMStruts2 Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts2-core</artifactId> <version>2.5.2</version> </dependency> </dependencies> <build> <finalName>MistraRMStruts2</finalName> <plugins> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <path>/${project.build.finalName}</path> <port>8080</port> <uriEncoding>UTF-8</uriEncoding> <finalName>${project.build.finalName}</finalName> <!-- 名称必须与配置文件的id名称一致 --> <server>tomcat7</server> </configuration> <!-- 在打包周期运行tomcat7 --> <executions> <execution> <phase>package</phase> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "http://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.devMode" value="true"></constant> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.locale" value="zh_CN"></constant> <package name="hurricane" extends="struts-default"> <action name="loginAction" class="com.mistra.ms.LoginAction" method="execute"> <result> /success.jsp </result> </action> </package> </struts>
web.xml
<web-app > <display-name>Archetype Created Web Application</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <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> </web-app>
LoginAction.java
package com.mistra.ms; import com.opensymphony.xwork2.ActionSupport; /** * Created by Administrator on 2017/12/28/028. */ public class LoginAction extends ActionSupport{ public String Name; public String getName() { return Name; } public void setName(String name) { Name = name; } @Override public String execute() throws Exception { return SUCCESS; } }
index.jsp
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ page pageEncoding="UTF-8"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <h2>Hello World!</h2> <form action="loginAction"> 姓名<input type='text' name="Name"><input type="submit" value="提交"> </form> </body> </html>
success.jsp
<%@ taglib uri="/struts-tags" prefix="s"%> <%@ page contentType="text/html; charset=UTF-8"%> <%@ page pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Welcome</title> </head> <body> Hello <s:property value="Name" /> </body> </html>
源码GitHub地址。
相关文章推荐
- Maven学习(五)- 使用Maven构建Struts2项目
- 实例学习maven 项目构建
- 实例学习maven 项目构建
- 使用maven构建struts2
- struts2入门 -Idea maven 构建项目
- Jersey 2.17 + Tomcat + Maven 构建restful service 实例
- Java-Web进阶系列(五)--maven构建struts2 web工程
- Jersey 2.17 + Tomcat + Maven 构建restful service 实例
- Maven学习(五)- 使用Maven构建Struts2项目
- 使用Eclipse构建Maven管理的Struts2应用
- 构建 shiro struts2 spring3 mybatis 的maven项目
- [Spring实战系列] - No.5 SpringMVC+Maven+Tomcat构建实例
- Maven 构建 Struts2 实现 基本 CURD Controller
- maven构建struts2+spring项目简单实例
- 使用maven构建web项目实例
- 使用maven构建web项目实例
- Maven学习(五)- 使用Maven构建Struts2项目
- Maven - 构建Struts2项目
- 使用Maven构建Struts2项目
- 详细描述用maven构建Struts2项目