struts2拦截器转化敏感字符
来源:互联网 发布:mac怎样新建文件夹 编辑:程序博客网 时间:2024/05/20 19:49
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" namespace="/" extends="struts-default"> <interceptors> <interceptor name="message" class="com.sxt.interceptors.MessageInterceptor"/> </interceptors> <action name="msg" class="com.sxt.action.MessageAction"> <result>MyJsp.jsp</result> <interceptor-ref name="message" /> <interceptor-ref name="defaultStack"/> </action> </package></struts> MessageAction.java package action; import com.opensymphony.xwork2.ActionSupport;public class MessageAction extends ActionSupport { private String msg;public String getMsg() {return msg;}public void setMsg(String msg) {this.msg = msg;}@Overridepublic String execute() throws Exception {return SUCCESS;}}MessageInterceptor.java package interceptors;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Set;import java.util.Map.Entry;import com.opensymphony.xwork2.Action;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionInvocation;import com.opensymphony.xwork2.interceptor.AbstractInterceptor;import com.sun.xml.internal.stream.Entity;import com.sxt.action.MessageAction;public class MessageInterceptor extends AbstractInterceptor {//本文只使用了一个参数msg@Overridepublic String intercept(ActionInvocation arg0) throws Exception { String msg = "";Map<String, Object> map = ActionContext.getContext().getParameters();Iterator it= map.entrySet().iterator(); //下面代码为:取出每一个参数while( it.hasNext()){System.out.println("-----------");Map.Entry<String, Object> mapentry= (Map.Entry<String, Object>) it.next(); // System.out.println(((String[])mapentry.getValue())[0]); msg = ((String[])mapentry.getValue())[0];}System.out.println(msg); //下面代码也可获取指定参数
// Map map = arg0.getInvocationContext().getParameters();<span style="white-space:pre"></span> //<span style="white-space:pre"></span>String[] message = (String[]) map.get("msg"); // msg = message[0];
String m =msg.replaceAll("TMD", "***");System.out.println(m);//将转换后的msg放入参数map Map params = new HashMap();params.put("msg", m);arg0.getInvocationContext().setParameters(params);
//或<span style="font-family: 微软雅黑, 'MS Sans Serif', sans-serif; font-size: 13px;">arg0.getInvocationContext().getParameters().put("msg",m);</span>
return arg0.invoke();}}index.jsp //使用ajax标签局部刷新显示结果 <%@ page language="java" import="java.util.*" pageEncoding="gbk"%><%@ taglib prefix="sx" uri="/struts-dojo-tags"%><html> <sx:head/> <body> <form action="msg" > 请输入:<input type="text" name="msg"/> <sx:submit targets="div1" value="提交"/> </form> <!-- sx:submit targets="div1"会将请求结果返回到div1 --> <sx:div id="div1"></sx:div> </body></html>MyJsp.jsp <%@ page language="java" import="java.util.*" pageEncoding="gbk"%><html> <body> 输入的内容为:${msg} </body></html>
0 0
- struts2拦截器转化敏感字符
- Struts中拦截器过滤敏感字符
- struts2拦截器屏蔽字符
- struts2的拦截器,替换掉敏感词汇
- AbstractInterceptor 字符拦截 struts2
- struts2拦截非法字符+防止反复提交
- 【Struts2】Struts2中拦截器
- struts2拦截器
- Struts2拦截器
- struts2.0拦截器
- struts2.0 拦截器
- struts2拦截器学习
- struts2 拦截器
- Struts2拦截器(Interceptor)
- struts2.0拦截器
- 用上struts2拦截器
- struts2拦截器简介
- Struts2:拦截器概述
- 09_EGIT插件的安装,Eclipse中克隆(clone),commit,push,pull操作演示
- 欢迎使用CSDN-markdown编辑器
- Ubuntu 下 python 安装 MySQLdb
- 酷融贷官网
- IOS读取文件类和常用方法
- struts2拦截器转化敏感字符
- linux内存映射mmap原理分析
- 编程之美----扩展问题
- 2015-07-29总结
- Unable to build the default ValidatorFactory
- Git push本地代码到github出错
- php开启openssl的方法
- excel的处理
- #if 0 ....#endif的作用