开发模式
Model Ⅰ
JSP + JDBC
Model Ⅱ
Servlet + JSP + JavaBean
MVC
模型-Model
视图-View
控制器-Controller
Struts2框架搭建
1.添加jar包
2.配置核心控制器
3.添加struts.xml
4.创建业务控制器
1.普通类-execute
2.实现接口-Action
3.继承父类-ActionSupport
Struts2配置
struts.xml的相关配置
package包
name
namespace
extends继承
struts-default
json-default
include导入其他的struts_*.xml
action
name
class
method
execute-默认
result
name
login
input
success
error
type
redirect
redirectAction
dispatcher-默认
chain
json
stream
constant-常量
也可以将常量配置到struts.properties
global-results
global-exception
interceptors
其他
servlet解耦
ActionContext
ServletActionContext
getRequest()
HttpServletRequest
getSession()
HttpServletSession
getResponse()
getApplication()
ognl和struts2标签
ognl
对象导航图语言
查询和显示数据的一种表达式语言
作用域
ValueStack
Action的实例
StackContext
ActionContext.put(key, value)
#request
#session
#application
#parameters
struts2标签
<%@ taglib uri="/struts-tags" prefix="s" %>
数据标签
property
date
set
控制标签
if
elseif
else
iterator
UI标签
form
textfield
textarea
submit
select
file
ajax标签
struts2验证框架
客户端验证
运行在客户端浏览器-javascript代码
用户体验好,但是不安全
服务器端验证
运行在服务器端-Java代码
验证的几种实现方式
1.execute - validate
2.execute - ActionName_validation.xml
3.others method - validateXxx
3.others method - ActionName_alias_validation.xml
验证标签:actionerror、fielderror
国际化+拦截器+ajax
国际化
语言-区域
zh_CN
zh_TW
en_US
en_GB
ar-...
resources_语言_区域.properties
struts2.xml配置struts.custome.i18n.resources
JSP:text标签
JSP:其他标签key
Action:super.getText("key")
JSP:property标签 value="getText('key')"
***.validate.xml:message标记key属性
拦截器
用于拦截Action,在Action执行前后去执行其他代码
struts2内置的拦截器
fileUpload
params
... ...
自定义拦截器
1.实现接口:Interceptor
2.继承类:AbstractInterceptor
3.继承类:MethodFilterInterceptor
拦截器栈
多个拦截器组成的集合
ajax
1.导入jar包2个
2.package extends json-default
action - result - type == json
ajax返回的结果为action类中所有的属性
includeProperties
excludeProperties
文件上传
1.添加jar包2个
2.Action添加属性
File img
String imgFileName
String imgContentType
struts.xml设置fileUpload拦截器的参数
多文件上传
将Action中的属性该为List<T>
Loading...