拦截器——替换表单中的敏感词
来源:互联网 发布:java 打印byte数组 编辑:程序博客网 时间:2024/05/21 22:31
RegistAction.javapackage tutorial;import java.text.DateFormat;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import com.opensymphony.xwork2.ActionSupport;public class RegisterAction extends ActionSupport {/** * */private static final long serialVersionUID = 1L;private String username;private Date birthday;private double height;private String sex;private String hobby;public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}public Date getBirthday() {return birthday;}public void setBirthday(Date birthday) {this.birthday = birthday;}public double getHeight() {return height;}public void setHeight(double height) {this.height = height;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getHobby() {return hobby;}public void setHobby(String hobby) {this.hobby = hobby;}public static long getSerialversionuid() {return serialVersionUID;}// 校验方法,用来输入校验public void validate() {// 校验是否输入用户名if (getUsername() == null || getUsername().trim().equals("")) {addFieldError("username",getText("nameNotNull"));}else //校验用户名长度if(username.length()<2||username.length()>50){addFieldError("username", getText("nameRange"));}// 校验是否输入密码if (getHeight()== 0.0) {addFieldError("height", getText("heightNotNull"));}//校验密码的组成与长度else if(height<100||height>250){addFieldError("height", getText("heightRange"));}DateFormat dateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); Date myDate1 = null; Date myDate2 = null;try {myDate1 = dateFormat1.parse("1900-01-01");myDate2 = dateFormat1.parse("2020-12-31"); } catch (ParseException e) {// TODO Auto-generated catch blocke.printStackTrace();} // 校验是否输入生日if (getBirthday() == null) {addFieldError("birthday", getText("birthdayNotNull"));} else// 校验是否输入正确的生日日期if (getBirthday().before(myDate1)||getBirthday().after(myDate2)) {addFieldError("birthday", getText("birthdayRange"));}}}TextInterceptor.javapackage tutorial;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;public class TextInterceptor extends AbstractInterceptor{/** * */private static final long serialVersionUID = 1L;@Overridepublic String intercept(ActionInvocation invocation) throws Exception {// TODO Auto-generated method stubObject object = invocation.getAction();if(object!=null){//判断object是否是Text的实例if(object instanceof RegisterAction){RegisterAction action = (RegisterAction)object;String username=action.getUsername();if(username.contains("obm")){username=username.replaceAll("obm", "***");action.setUsername(username);}return invocation.invoke();}else{return Action.LOGIN;}}return Action.LOGIN;}}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><package name="default" extends="struts-default"><interceptors><interceptor name="replace" class="tutorial.TextInterceptor"></interceptor></interceptors><!-- Action名字,类以及导航页面定义 --><!-- 通过Action类处理才导航的的Action定义 --><action name="Register" class="tutorial.RegisterAction"><!-- 配置拦截器 --><interceptor-ref name="validationWorkflowStack"/><result name="input">reg.jsp</result><result name="success">ok.jsp</result><interceptor-ref name = "defaultStack"></interceptor-ref><interceptor-ref name = "replace"></interceptor-ref></action></package></struts>reg.jsp<body> <h1><s:text name="title"></s:text></h1> <form name="form1" method="post" action="Register"> <s:textfield name="username" label="%{getText('Name')}"></s:textfield><br/> <s:textfield name="birthday" label="%{getText('Birthday')}"></s:textfield><br/> <s:textfield name="height" label="%{getText('Height')}"></s:textfield><br/> <label ><s:text name="Sex"/></label> <input type="radio" name="sex" value="male" checked="checked" ><s:text name="male"/> <input type="radio" name="sex" value="female"><s:text name="female"/><br/> <s:select label = "%{getText('Hobby')}" list="{'其他','文字','体育'}" name="hobby"></s:select><br/> <input type="submit"name="submit" value='<s:text name="submit"/>' > </form> </body>
阅读全文
0 0
- 拦截器——替换表单中的敏感词
- struts2的拦截器,替换掉敏感词汇
- 富文本编辑器中的敏感词替换
- Filter——实现敏感字拦截
- 敏感词替换
- PHP 敏感词替换
- php 敏感词替换
- 敏感词替换
- java过滤敏感词替换**
- [j2ee]自定义过滤器拦截敏感词
- struts2拦截器转化敏感字符
- Struts中拦截器过滤敏感字符
- 令牌拦截器—-struts2表单重复提交
- 一个替换敏感词的filter
- javascript 之 星号替换敏感词
- DFA算法过滤敏感词,替换为*
- DFA算法过滤敏感词,替换为*
- 循环替换字符串,可用户替换敏感词
- android-uevent 简记
- 高亮显示
- shell脚本循环建立文件夹的bug
- 高亮显示
- centos7.2 安装zookeeper并配置zookeeper集群
- 拦截器——替换表单中的敏感词
- spark官方文档阅读笔记1
- 常用链接
- 淘宝滑动界面
- 右下角弹出广告
- czl蒟蒻的模板库2——FASTIO
- 网络字节序转化
- isNotEmpty 和isNotBlank的区别
- 友盟集成QQ第三方登录