最近在系统性的学习maven,碰到搭建struts2环境,特此记录一下。

1.创建maven工程

2.添加依赖

pom.xml文件内容如下

<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>com.dylan</groupId>
<artifactId>02_maven_struts2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging> <dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.16</version>
</dependency>
</dependencies> <!--添加JDK插件 -->
<build>
<finalName>02_maven_struts2</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>

3.在web.xml中添加struts2核心过滤器

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>02_maven_struts2</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.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>

4.编写Action

package action;

import com.opensymphony.xwork2.ActionSupport;

public class CustomerAction extends ActionSupport {

	/**
*
*/
private static final long serialVersionUID = 1L; public String save() throws Exception {
System.out.println("方法执行成功!");
return SUCCESS;
} }

5.编写success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" 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>Insert title here</title>
</head>
<body>
<h1>方法执行成功后的页面!</h1>
</body>
</html>

6.配置struts.xml

<!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.enable.DynamicMethodInvocation" value="true"
/> <constant name="struts.devMode" value="true"></constant> -->
<package name="demo" namespace="/" extends="struts-default">
<action name="customerAction_*" class="action.CustomerAction"
method="{1}">
<result name="success">success.jsp</result>
</action>
</package>
</struts>

6.测试

访问:http://localhost:8080/02_maven_struts2/customerAction_save.action

完整项目下载链接:

https://download.csdn.net/download/indexman/10469572

Eclipse搭建Struts2项目的更多相关文章

  1. Eclipse搭建maven项目的流程,聚合所有的子模块项目

    Eclipse搭建maven项目的流程 2018年03月01日 15:47:03 阅读数:22 1:搭建parent工程,用来聚合所有的子模块项目 2:搭建公共使用的模块common 这里你要点击空白 ...

  2. Eclipse搭建struts2环境

    搭建struts2环境 大的方面分为三步: 1. 加入jar包 2. 在web.xml中配置struts2 3. 添加struts2的配置文件struts.xml 下面是详细步骤: 1. 新建一个Dy ...

  3. eclipse搭建struts2环境及所遇到的问题

    最近几天一直在搭建struts2框架,本身struts2框架的搭建是非常简单的,但不知道为什么最近就是总是报错,报了一大串的错 首先就是每次在类的根路径下创建struts.xml时,就报错,也不知道为 ...

  4. Eclipse搭建Maven项目并上传SVN备份

    本文出自:http://www.cnblogs.com/2186009311CFF/p/7226127.html 背景:近段时间在学着Java,想着用Java做BS的项目.但是项目一遇到问题又要重做, ...

  5. eclipse 搭建maven项目

    最近重新搭建项目把日常用到的东西都记录一下. 创建maven项目(maven4.4以后都自带maven了)   1,创建一个Maven parent  主要是各个项目之间的依赖 使用eclipse 创 ...

  6. 用eclipse 搭建struts2环境

    一,下载struts2对应的jar包,(http://struts.apache.org/download.cgi#struts2514.1),我一般下载struts2.3版本的 二,打开eclips ...

  7. 转载:eclipse 搭建SSH项目(第二篇,有具体的项目例子)

    原文地址:http://blog.csdn.net/yeohcooller/article/details/9316923 读博文前应该注意: 本文提纲:本文通过一个用户注册的实例讲解SSH的整合.创 ...

  8. 转载:eclipse 搭建SSH项目(第一篇)

    第一篇:原文地址:http://blog.csdn.net/aaaaaaaa0705/article/details/6288431(虽然没有具体的例子,不过逻辑性强点,比较容易看懂) SSH框架是最 ...

  9. (A)eclipse搭建springboot项目入门

    网上许多资料都是用idea的,但是我个人用eclipse习惯了,所以就在eclipse里面自己尝试着写了一个hello. 然而项目建好后却迟迟不能访问!!!网上搜了许多资料都不靠谱! 虽然最后能看到h ...

  10. Eclipse 搭建Struts2

    Eclipse版本 Mars Release (4.5.0) Struts版本 struts-2.5.20 下载地址:https://struts.apache.org/download.cgi#st ...

随机推荐

  1. [转帖]Nginx access log 按日期保存记录

    https://cloud.tencent.com/developer/article/1958304 $time_iso8601    生成格式:2021-09-18T15:16:35+08:00 ...

  2. [转帖]自动清理_详解centos7和centos6系统的/tmp目录自动清理规则及区别

    概述 分享最近应用碰到的一个奇怪bug,一开始以为是代码上的问题,找了一段时间发现居然是因为系统的一个自动清理规则导致,下面一起来看看吧~ 一.应用报错: logwire.core.exception ...

  3. [转帖]使用 TiUP 部署 TiDB 集群

    https://docs.pingcap.com/zh/tidb/stable/production-deployment-using-tiup TiUP 是 TiDB 4.0 版本引入的集群运维工具 ...

  4. [转帖]Kubernetes部署Minio集群存储的选择,使用DirectPV CSI作为分布式存储的最佳实践

    Kubernetes部署Minio集群存储的选择,使用DirectPV CSI作为分布式存储的最佳实践 个人理解浅谈 1. 关于在kubernetes上部署分布式存储服务,K8s存储的选择 非云环境部 ...

  5. shell的date的部分处理--需要记住..

    在Linux中,可以使用date命令获取日期, date 获取当前完整日期 date --date="3 days ago" 获取3天前的完整日期 date --date=&quo ...

  6. [转帖]VCSA6.7证书过期后的处置方法

    0x00 环境说明 一台测试的ESXI主机,元旦之后已然发现证书已过期,具体现象:VCenter无法登录,一直提示输入用户名和密码,ESXI主机web页面无法登录.重启VC以后,报故障503错误. / ...

  7. 六个节点三主三从Redis集群最简单搭建方法

    背景 一个服务器上面的三主三从的界面太low,容易出问题. 为了验证高可用, 我这边使用六台机器进行了三主三从的搭建. 模仿开源版的一键搭建集群的脚本进行使用,感觉非常简单,这里简单进行一下总结. 环 ...

  8. vue启动报错_interopRequireDefault is not a function

    起因 今天接触一个项目vue. 在安装好环境之后,启动的时候报错_interopRequireDefault is not a function 解决的办法:我觉得可能是因为node_modules安 ...

  9. vue3.0中reactive的正确使用姿势

    场景 在项目开发的时候,前端肯定是先写静态页面 在静态页面写好之后 然后就可以与后端对接数据了[高兴] 但是在对接接口的时候 我们会发现后端返回来的字段与前端在页面上写的可能不一致 这个时候有意思的事 ...

  10. (数据科学学习手札122)Python+Dash快速web应用开发——内网穿透篇

    由我开源的先进Dash组件库feffery-antd-components正处于早期测试版本阶段,欢迎前往官网http://fac.feffery.tech/了解更多 1 简介 这是我的系列教程Pyt ...