-------------------------siwuxie095

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

Maven 项目整合 Struts2 框架

 
 

 
 

1、先创建
Maven 项目:maven-struts2

 
 

 
 

 
 

注意:要勾选跳过原型选项

跳过骨架选项

 
 

 
 

 
 

 
 

 
 

2、创建完成,项目目录结构一览:

 
 

 
 

 
 

 
 

 
 

3、

pom.xml 中添加 struts2-core 的依赖

 
 

<dependency>

<groupId>org.apache.struts</groupId>

<artifactId>struts2-core</artifactId>

<version>2.3.33</version>

</dependency>

 
 

 
 

 
 

 
 

4、不难发现,除了手动添加的依赖
struts2-core,

struts2-core 的依赖也自动添加进来了

 
 

 
 

 
 

 
 

 
 

5、在
src/main/java 目录下创建 Action 类

 
 

UserAction.java:

 
 

package com.siwuxie095.action;

 
 

import com.opensymphony.xwork2.ActionSupport;

 
 

public class UserAction extends ActionSupport {

 
 

public String add() {

System.out.println("----- add -----");

return
"add";

}

 

}

 
 

 
 

 
 

 
 

6、在
src/main/resources 目录下创建 Struts2 核心配置文件

 
 

struts.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"
?>

<!DOCTYPE struts PUBLIC

"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"

"http://struts.apache.org/dtds/struts-2.3.dtd">

 
 

<struts>

 
 

<package
name="demo"
extends="struts-default"
namespace="/">

 

<action
name="user_*"
class="com.siwuxie095.action.UserAction"
method="{1}">

<result
name="add">/index.jsp</result>

</action>

 

</package>

 
 

</struts>

 
 

 
 

 
 

 
 

7、在
src/main/webapp 目录下创建 JSP 页面

 
 

index.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>首页</title>

</head>

<body>

<h1>添加成功!</h1>

</body>

</html>

 
 

 
 

 
 

 
 

8、此时,index.jsp 无法编译通过,向 pom.xml 中添加依赖
jsp-api

 
 

<!--

创建的 JSP 文件需要 jsp-api 依赖才能编译

通过,但因为 Tomcat 中已经有了该 jar 包,

所以将依赖范围设置为 provided

 

同时,servlet-api 是 jsp-api 的依赖,将

自动添加进来

 

其实,这里只添加 servlet-api 也是可以编译

通过的

 

综上,共有三种解决方法:

(1)手动添加 jsp-api 依赖,servlet-api 因

为是 jsp-api 的依赖,也将自动添加进来

(2)手动添加 servlet-api 依赖

(3)手动添加 jsp-api 和 servlet-api 依赖

 

-->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jsp-api</artifactId>

<version>2.0</version>

<scope>provided</scope>

</dependency>

 
 

 
 

 
 

 
 

9、综上,该
Maven 项目的核心配置文件如下:

 
 

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>

<!-- 当前 Maven 项目的坐标信息 -->

<groupId>com.siwuxie095.maven</groupId>

<artifactId>maven-struts2</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>war</packaging>

 

 

<dependencies>

 

<!--

只需要添加 struts2-core 一个依赖,

struts2-core 的依赖就会自动添加

进来

-->

<dependency>

<groupId>org.apache.struts</groupId>

<artifactId>struts2-core</artifactId>

<version>2.3.33</version>

</dependency>

 

<!--

创建的 JSP 文件需要 jsp-api 依赖才能编译

通过,但因为 Tomcat 中已经有了该 jar 包,

所以将依赖范围设置为 provided

 

同时,servlet-api 是 jsp-api 的依赖,将

自动添加进来

 

其实,这里只添加 servlet-api 也是可以编译

通过的

 

综上,共有三种解决方法:

(1)手动添加 jsp-api 依赖,servlet-api 因

为是 jsp-api 的依赖,也将自动添加进来

(2)手动添加 servlet-api 依赖

(3)手动添加 jsp-api 和 servlet-api 依赖

 

-->

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>jsp-api</artifactId>

<version>2.0</version>

<scope>provided</scope>

</dependency>

 

</dependencies>

 

 

</project>

 
 

 
 

 
 

 
 

10、最后,别忘了在部署描述文件中配置 Struts2 核心过滤器

 
 

web.xml:

 
 

<?xml
version="1.0"
encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<welcome-file-list>

<welcome-file>index.jsp</welcome-file>

</welcome-file-list>

 

<!-- 配置 Struts2 核心过滤器 -->

<filter>

<filter-name>struts2</filter-name>

<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

</filter>

<filter-mapping>

<filter-name>struts2</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

 

</web-app>

 
 

 
 

 
 

 
 

11、访问路径

 
 

http://localhost:8080/maven-struts2/user_add.action

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

 
 

【made by siwuxie095】

Maven项目整合Struts2框架的更多相关文章

  1. Maven项目整合SSH框架

    ---------------------siwuxie095                                         Maven 项目整合 SSH 框架         创建 ...

  2. spring springmvc mybatis maven 项目整合示例-导航页面

    spring原理 实践解析-简单的helloworld spring原理案例-基本项目搭建 01 spring framework 下载 官网下载spring jar包 spring原理案例-基本项目 ...

  3. 整合Struts2框架和Spring框架

    -----------------------siwuxie095                                 整合 Struts2 框架和 Spring 框架         1 ...

  4. Spring整合Struts2框架的第二种方式(Action由Spring框架来创建)(推荐大家来使用的)

    1. spring整合struts的基本操作见我的博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2框架整 ...

  5. Spring整合Struts2框架的第一种方式(Action由Struts2框架来创建)。在我的上一篇博文中介绍的通过web工厂的方式获取servcie的方法因为太麻烦,所以开发的时候不会使用。

    1. spring整合struts的基本操作见我的上一篇博文:https://www.cnblogs.com/wyhluckdog/p/10140588.html,这里面将spring与struts2 ...

  6. Spring 框架整合Struts2 框架和 Hibernate 框架

    1. Spring 框架整合 Struts2 框架 // [第一种整合方式(不推荐)](http://www.cnblogs.com/linkworld/p/7718274.html) // 从 Se ...

  7. 【SSM】Eclipse使用Maven创建Web项目+整合SSM框架

    自己接触ssm框架有一段时间了,从最早的接触新版ITOO项目的(SSM/H+Dobbu zk),再到自己近期来学习到的<淘淘商城>一个ssm框架的电商项目.用过,但是还真的没有自己搭建过, ...

  8. Eclipse使用Maven创建Web项目+整合SSM框架

    一.准备环境: maven:apache-maven-3.2.3 jdk:jdk1.8.0_25 tomcat:tomcat-9.0 二.配置Maven.jdk 1.Window——>Prefe ...

  9. 通过idea创建Maven项目整合Spring+spring mvc+mybatis

    创建项目 File→new→project             然后就不断next直到项目面板出来 设置文件夹         注意:这里我个人习惯,在java下还建了ssm文件夹,然后再cont ...

随机推荐

  1. php使用inotify实现队列处理

    php使用inotify实现队列处理参考如下文章:http://blog.jiunile.com/php%E4%BD%BF%E7%94%A8inotify%E5%AE%9E%E7%8E%B0%E9%9 ...

  2. Hibernate 零散知识点

    1 get方法和load方法查询时的区别: 如果在缓存中没有找到相应的对象,get会直接访问数据库并返回一个完全初始化的对象,过程中可能涉及多次数据库调用:而load会返回一个代理对象,只有在对象ge ...

  3. 对 Spring 的核心(AOP 和 IOC)的理解(大白话)

    Spring 首先它是一个开源而轻量级的框架.其核心容器的主要组件是Bean工厂(BeanFactory).Bean工厂使用控制反转(IOC)模式来降低程序代码之间的耦合度,并提供了面向切面编程(AO ...

  4. HTML5 通过文件输入框读取文件为base64文件, 并借助canvas压缩 FileReader, files, drawImage

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  5. linux的基础

    vmtools 的安装:作用 ——>共享linux和windows的文件夹 reboot 重启 远程登录 : 远程登录时要打开sshd(监视22端口) 怎么设施sshd: 打开远端,输入setu ...

  6. Delphi 解析HTML

    uses mshtml; IHTMLEleMent.ID; IHTMLEleMent.tagName; IHTMLEleMent.title;elmt._className;elmt.getAttri ...

  7. discuz 修改积分策略( 在周期中添加"每周" )

    在  source/admincp/admincp_credits.php 文件中, ctrl+f 搜索  $lang['setting_credits_policy_cycletype_1'] 处, ...

  8. bat 笔记 一

    echo 有两个参数 off 和 on 注意echo前面要加个@才生效 当 @echo off的时候就是将doc命令将前面的路径去掉,默认其实就是@echo on显示路径: 默认的状态: 输入@ech ...

  9. as3 加载gif loader

    as3原生不支持gif动态图 loader 加载gif ,内容只是以bitmap加载进来 需要动态,另外衍生类: https://files.cnblogs.com/files/dt1991/GifL ...

  10. Several ports (8005, 8080, 8009) required by Tomcat v7.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To sta

    有三种导致这种错误的原因. 第一个: 是因为tomcat的服务没有被关闭所导致的,将服务关闭即可 找到tomcat的安装目录,进入bin文件夹,找到tomcat7w.exe,双击这个文件,点击stop ...