struts2的数据校验&常用OGNL表达式&ActionSupport
来源:互联网 发布:1064 mysql 编辑:程序博客网 时间:2024/06/10 04:19
数据校验
struts2 的后台校验
注意: 文件名必须是UserAction-user_register-validation.xml
即格式:[Action名]-[对应的action]-validation.xml
1. 在这里校验的加过会存储在struts的值栈中
2. 在jsp界面使用 <s:field fieldName=""/>
标签显示对应的错误信息
3. 在struts.xml文件中必须配置 <result name="input">/WEB-INF/jsp/register.jsp</result>
示例
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE validators PUBLIC "-//Apache Struts//XWork Validator 1.0.3//EN" "http://struts.apache.org/dtds/xwork-validator-1.0.3.dtd"><validators> <!-- 校验用户名 --> <field name="username"> <field-validator type="requiredstring"> <message>用户名不能为空!</message> </field-validator> </field> <!-- 校验邮箱 --> <field name="email"> <field-validator type="email"> <message>邮箱格式不正确!</message> </field-validator> </field></validators>
这里示例校验的是User类的字段包报的位置:
前台jsp界面显示
配置标签:
1. <s:fielderror fieldName="password"/>
:对应struts的数据校验xml的配置字段
2. <s:actionerror/>
:在Action
类中定义的this.addActionError("xxx")
方法
3.<s:actionmessage/>
对应 this.addActionMessage("xxx")
方法
常用 OGNL表达式
- 判断
<s:if test=""/>xxx<s:if>
和<s:else>xxx<s:else>
在jsp页面获得session的值
<s:property value="#session.xxx" />
Action
类implements RequestAware
并实现默认方法
private Map<String, Object>request; public void setRequest(Map<String, Object> arg0) { this.request = arg0; } request.put("xxx",xxx);
- jsp页面回显:
#request.xxx
ActionSupport中包含的对象
ServletActionContext和
获得request和respone对象
ServletActionContext.getRequest().getSession() .setAttribute("xxx",xxx);
jsp页面引用session中存放的值 #session.xxx
ActionContext
- 值栈中存值:
ActionContext.getContext().getValueStack().set("xxx", xxx);
jsp页面引用
知识通过变量名引用
<s:property value="xxx" />
- ModelDriven模型驱动
首先在action中已经实现了bean对象的模型驱动
例如:
public class ProductAction extends ActionSupport implements ModelDriven{
//模型驱动
private Product product = new Product();
public Product getModel() {
return product;
}
}
<s:property value="model.product" />
- session中存值:
ActionContext.getContext().getSession().put(key, value)
在jsp页面获得xxx的值:
<s:property value="#session.xxx" />
0 0
- struts2的数据校验&常用OGNL表达式&ActionSupport
- Struts2常用的类ActionSupport
- struts2中ActionSupport校验
- Struts2的数据校验(Action类必须要继承ActionSupport类)
- struts2的OGNL表达式
- struts2的OGNL表达式
- struts2的OGNL表达式
- Struts2的OGNL表达式
- Struts2的OGNL表达式
- Struts2的OGNL 表达式
- struts2的ognl表达式
- struts2的OGNL表达式
- Struts2的OGNL表达式
- Struts2学习总结(3)--值栈,Ognl表达式,Struts标签库,国际化,数据校验,拦截器
- Struts2学习总结(3)--值栈,Ognl表达式,Struts标签库,国际化,数据校验,拦截器
- 常用的OGNL表达式
- 常用的ognl表达式
- Struts2的OGNL表达式语言
- ESP8266--Linux-TCPServer-MySQL
- leetcode [Binary Tree Level Order Traversal II]
- 各大排序算法自己总结
- window10安装docker时报错 hyper-v feature is not enabled
- Jeff and Rounding
- struts2的数据校验&常用OGNL表达式&ActionSupport
- nginx配置文件nginx.conf实例
- 设计模式(16)-状态模式
- 2017浙江省选一试第一天游记
- 类模板模拟实现STL中Vector
- nginx配置文件nginx.conf中文注释
- 设计模式(六)适配器模式
- hdu 2102
- 使用FileUpload组件完成文件下载