Struts2 使用基本流程
使用流程:
1、引入Struts 2的库文件:
将“common-logging-1.0.4.jar”、“freemaker-2.3.8.jar”、“struts2-core-2.0.11.1.jar”、“xwork-2.0.4.jar”和“ognl-2.6.11.jar”类库复制到Web项目的WEB-INF/lib目录下。
2、编辑Web项目中的“web.xml”配置文件,在配置文件中增加Struts 2核心Filter的配置:
web.xml配置文件<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> <!-- 定义核心Filter -->
<filter>
<!-- 定义核心Filter的名称 -->
<filter-name>struts2</filter-name>
<!-- 定义核心Filter的实现类 -->
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<!-- 定义核心Filter的名称 -->
<filter-name>struts2</filter-name>
<!-- 使用该核心Filter来接受所有的Web请求 -->
<url-pattern>/*</url-pattern>
</filter-mapping></web-app>
3、新建控制器类Action
4、配置Action,修改struts.xml,其中包括指定Action的实现类以及Action处理结果与视图资源文件之间的映射:
struts.xml配置文件<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- Action必须放在指定的包命名空间中 -->
<package name="structs2" extends="struts-default">
<!-- 定义login的Action,其实现类为com.chaos.structs2.action.LoginAction -->
<action name="aaa" class="com.chaos.structs2.action.LoginAction">
<!-- 定义处理结果与视图资源之间的关系 -->
<result name="success">/login_success.jsp</result>
<result name="error">/login_error.jsp</result>
</action>
</package>
</struts>
Struts2 使用基本流程的更多相关文章
- struts2 框架处理流程
struts2 框架处理流程 流程图如下: 注意:StrutsPrepareAndExecuteFilter替代了2.1.3以前的FilterDispatcher过滤器,使得在执行Action之前可以 ...
- Struts2的基本流程的详细介绍
Struts2基本流程 概述: Struts2框架由三部分构成:核心控制器.业务控制器和用户实现的业务逻辑组件.在这三部分中,struts2框架提供了核心控制器StrutsPrepareAndExec ...
- Struts2的运行流程以及关键拦截器介绍
Struts2的运行流程 1.ActionProxy是Action的一个代理类,也就是说Action的调用是通过ActionProxy实现的,其实就是调用了ActionProxy.execute()方 ...
- Java Struts2 的请求处理流程详解
一.Struts2的处理流程: 客户端产生一个HttpServletRequest的请求,该请求被提交到一系列的标准过滤器(Filter)组建链中(如ActionContextCleanUp:它主要是 ...
- struts2处理请求流程详解
struts2大概分为两块:一是struts2系统初始化,二是struts2处理请求,对请求作出响应. 下面就说说个人对struts2对请求处理流程的理解: 下面是StrutsPrepareAndEx ...
- java框架篇---Struts2的处理流程
一.Struts2的处理流程: 客户端产生一个HttpServletRequest的请求,该请求被提交到一系列的标准过滤器(Filter)组建链中(如ActionContextCleanUp:它主要是 ...
- struts2系列(一):struts2入门(struts2的产生、struts2的工作流程、搭建struts2开发环境)
一. struts2的产生 struts1的缺点: 1. ActionForm过多,而且这个ActionForm在很大程度上又和VO(POJO)重复 ...
- Struts2 第三讲 -- Struts2的处理流程
4.Struts2的处理流程 以下是struts-defautl.xml中的拦截器 建议通过这个struts-default的副本查看,更形象 它实现了很多的功能,其中包括国际化,文件上传,类型转换, ...
- Struts2的工作流程分析
Struts2的工作流程分析 Posted on 2011-02-22 09:32 概述 本章讲述Struts2的工作原理. 读者如果曾经学习过Struts1.x或者有过Struts1.x的开发经验, ...
- java之struts2的执行流程讲解(1)
1.struts2的执行流程 请求--->Tomcat(判读项目是否存在)--->项目的web.xml--->struts2的核心过滤器 --->判读请求的资源(hello.a ...
随机推荐
- Java Nashorn--Part 2
在命令行中执行 JavaScript 现在我们有一个 my_script.js 文件,想在 Nashorn 下执行,则需要在命令行下执行该命令: jrunscript my_script.js jru ...
- SQL SERVER 的排序规则
有时候查询数据库的时候会发现(比如做重名检查的时候):数据库的查询时对大小写不敏感的,也就是 A 和 a 是一样的. 也就是说 select * from tabletest where name = ...
- React Native在开发过程中遇到的一些问题(俗称:坑)
4900 服务器地址错误 运行时产生以下错误:Could not connect to development server. 1.URL地址设置 问题: Could not connect to d ...
- 关于Suppressing notification from package com.xxx.xxx by user request.的异常
其实以下都是废话. 如果你的测试的真机或者是模拟器是android4.1以上, 就有可能遇到这个Toast或者通知不能弹出. 自己不懂为什么. 想想你自己的应用设置是否有勾上这个 没有的话.就活该显示 ...
- python 给文件批量加‘“’ ”,"
file = open('face.txt','r') filew = open('face1.txt','w') try: for line in file: print(line) if line ...
- MinGW环境libssh2安装
由于实习工作中要用到基于sftp协议开发一个网络程序,同时要实现运行在Windows平台上,找来找去就这个libssh2库好用,在网络上算是有那么一点点的文档可以看.这个库还不是现成的,还要进行源代码 ...
- [Windows Azure] Create a Virtual Network for Site-to-Site Cross-Premises Connectivity
Create a Virtual Network for Site-to-Site Cross-Premises Connectivity This tutorial walks you throug ...
- [Windows Azure] How to Monitor Cloud Services
How to Monitor Cloud Services To use this feature and other new Windows Azure capabilities, sign up ...
- 每日英语:America The Vulgar
'What's celebrity sex, Dad?' It was my 7-year-old son, who had been looking over my shoulder at my c ...
- Swift中Notification.Name这么难用怎么办
Swift中Notification.Name这么难用怎么办 以前的发送通知的参数就是一个简单的字符串: NSNotificationCenter.defaultCenter().post(" ...