使用Struts2流程:

1.导入Struts2类包

2.在Web源代码文件夹中,创建名为struts.xml的配置文件。在其中定义Action对象,其关键代码如下:

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="Mypackage" namespace="/" extends="struts-default">
<!-- 定义Action -->
<action name="first">
<!-- 定义处理成功后的映射界面 -->
<result>/first.html</result>
</action>
</package>
</struts>

3.在web.xml文件中声明Struts2提供的过滤器,类名为"org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter"

<?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" id="WebApp_ID" version="3.1">
<display-name>Struts2First</display-name>
<filter> <!-- 配置Struct2过滤器 -->
<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>
<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>
</web-app>

4.初始界面index.jsp:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href="first.action">跳转</a> <!-- 点击链接后,请求交给名为first的Action处理 -->
</body>
</html>

5.处理后的映射界面first.jsp:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
我的第一个struts2实例
</body>
</html>

Struts相关的更多相关文章

  1. (原)Struts 相关资源下载

    官网:http://struts.apache.org 点击[Download],进入页面如下,可以看到下载的资源: 点击[struts-2.3.20-all.zip],就能获取Struts2项目所有 ...

  2. struts快速入门第一篇 —— struts相关XML配置映射及讲解

    我们回忆一下在学习JavaWeb过程中(Jsp + servlet编程)所感受到的Servlet的不足: 1 Servllet很多时,web.xml中的代码会很多.这样一来,维护起来就不方便,不利于团 ...

  3. Struts框架——(二)Struts原理with登录实例

    二. Struts基本工作流程 假设现在有以下情景: 用户正在浏览一个用STRUTS的技术构建的网站主页,主页上有个登陆表单,用户填好登陆名和密码,单击"登陆"按钮,就激活了以下一 ...

  4. struts理解

    最近大家都在找工作,我好迷茫,觉得自己会的东西太少了.所以决定开始学习SSH三大框架. 首先是struts. struts是基于mvc模式的框架.(struts其实也是servlet封装,提高开发效率 ...

  5. Struts

    Struts是基于MVC的框架,它进一步的对MVC进行了封装. MVC 概念 MVC全名是Model View Controller,是模型(model)—视图(view)—控制器(controlle ...

  6. [转]Struts1.x系列教程(1):用MyEclipse开发第一个Struts程序

    转载地址:http://www.blogjava.net/nokiaguy/archive/2009/01/13/251101.html 本系列教程将详细介绍Struts 1.x的基本原理和使用方法, ...

  7. 第一个struts案例及分析

    软件中的框架,是一种半成品: 我们项目开发需要在框架的基础上进行!因为框架已经实现了一些功能,这样就可以提高开发效率! Struts2 = struts1  +  xwork (struts是基于MV ...

  8. 使用struts+spring+hibernate组装web应用

    这篇文章将讨论怎样组合几个着名的框架去做到松耦合的目的,怎样建立你的构架,怎样让你的各个应用层保持一致.富于挑战的是:组合这些框架使得每一层都以一种松耦合的方式彼此沟通,而与底层的技术无关.这篇文章将 ...

  9. Struts1——从BeanUtils看struts的实现原理2

        上一篇博客中我们简单的介绍了BeanUtils的使用.以及其最主要的原理,今天我们进一步的理解这个类在Struts1中的使用.     首先我们先回想一下搭建一个简单的基于Struts1框架的 ...

随机推荐

  1. JavaScript中的 offset, client,scroll

    在js 中我们要用到的 offset, client, scroll 在这我把自己理解的给大家分享一下. offset div.offsetTop 指div距离上方或上层控件的距离,单位像素 div. ...

  2. android-获得".apk"文件的相关信息。包名、版本号等等

    String filePath = "/sdcard/feijiedemo.apk"; PackageManager packageManager = getPackageMana ...

  3. awk命令详解

    搜索 纠正错误  添加实例 awk 文本和数据进行处理的编程语言 补充说明 awk 是一种编程语言,用于在linux/unix下对文本和数据进行处理.数据可以来自标准输入(stdin).一个或多个文件 ...

  4. 取两个String数组的交集

    import org.testng.annotations.Test; import java.util.HashMap; import java.util.LinkedList; import ja ...

  5. BZOJ 4184: shallot

    Description 在某时刻加入或删除一个点,问每个时刻的集合中能异或出来的最大值是多少. Sol 线段树+按时间分治+线性基. 按时间分治可以用 \(logn\) 的时间来换取不进行删除的操作. ...

  6. setprecision **fixed

    #include <iostream> #include <iomanip> using namespace std; int main( void ) { const dou ...

  7. linux git实现代理

    说明  Git 目前支持的三种协议 git://.ssh:// 和 http://,使用git:// 和 http://比较多,ssh://忽略,FQ后可以直接加快同步google和github代码. ...

  8. 在linux下使用curl访问 多参数url GET参数问题

    一.在Crontab中使用PHP执行脚本 就像在Crontab中调用普通的shell脚本一样(具体Crontab用法),使用PHP程序来调用PHP脚本.每一小时执行myscript.php如下: # ...

  9. [MySQL] MySQL存储过程常用的函数

    一.字符串类 CHARSET(str) //返回字串字符集 CONCAT (string2  [,... ]) //连接字串 INSTR (string ,substring ) //返回substr ...

  10. ASP.NET SignalR入门

    前言 之前在培训ASP.NET WebAPI的时候有提过SignalR这个技术,但当时只是讲了是用来做什么的,并没有多说.因为自己也是画图找资料的时候见到的.后来当一直关注的前端大神贤心发布LayIM ...