Struts2初级教程01 hello world
来源:互联网 发布:手机安装手电筒软件 编辑:程序博客网 时间:2024/05/17 09:23
一.新建一个web项目struts2的web应用所需要的最少类库
struts2-core-2.0.11.jarstruts2框架的核心类库xwork-2.0.4.jarXWork类库,struts2在基上构建ognl-2.6.11.jarstruts2框架使用的一种表达式语言freemarker-2.3.8.jarstruts2的UI标签的模板使用FreeMarker编写commons-logging-1.0.4.jar日志记录用二.在web.xml文件中配置FilterDispatcher
struts2框架是基于MVC模式开发的,它提供了一个控制器.用于对所有请求进行统一处理.这个控制器是由一个名为FilterDispatcher的Servlet过滤器来充当的.
<filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping>
三.编写Action类
一个action就是一段只有特定的URL被请求时才会执行的代码.action执行的结果,通常都对应着一个要呈现给用户的result,这个result可以是HTML,PDF,Excel.其配置在struts.xml中.
在Struts2中可以用一个普通的类作为Action类,只要这个类提供execute方法,如
public class TestAction {public String execute() throws Exception {System.out.println("你要执行的code");return "SUCCESS";}}
也可实现接口com.opensymphony.xwork2.Action,接口中定义了execute方法外,还有常常量.如:
package com.opensymphony.xwork2;public abstract interface Action{ public static final String SUCCESS = "success"; public static final String NONE = "none"; public static final String ERROR = "error"; public static final String INPUT = "input"; public static final String LOGIN = "login"; public abstract String execute() throws Exception;}在开发中常用继承类com.opensymphony.xwork2.ActionSupport,这个类也是实现了 com.opensymphony.xwork2.Action接口.
在所有action必须返回一个字条串类型的结果代码,以标识要呈现给用户的result.
涉及到的代码也相对简单,在这里就不贴出来了...
- struts2初级教程01 hello world
- Struts2初级教程01 hello world
- python PyQt5初级教程hello world
- python PyQt5初级教程hello world
- Struts2 学习笔记01 Hello World !
- Struts2 Hello World实例
- Struts2 Hello World 实例
- struts2 hello world 搭建
- Struts2 Hello World 实例
- Struts2 Hello World 实例
- Struts2 Hello World 实例
- Struts2入门 Hello world
- Struts2入门教程-Hello World
- 笔记:Struts2 Hello World实例
- Struts2的hello world教程
- Struts2 第一篇 Hello World
- Struts2入门教程-Hello World!
- 10002---Struts2 的 Hello World
- C#优先级
- 子库转移 杂项出入库脚本
- C# TextBox中只能输入数字的几种常用方法(C#)
- linux下直接修改IP、网关、DNS
- Android全屏
- Struts2初级教程01 hello world
- wince Qt QML
- error LNK2005 已经在***.obj中定义 错误主要原因
- add constraint方法添加约束
- 【转】不使用第三方变量交换两个变量的值
- Qt入门-中文显示
- Android蓝牙操作
- 使用单例模式实现自己的HttpClient工具类
- 网站备案前置审批