Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > jsp框架

Struts过滤xss攻击的解决办法

来源:中文源码网    浏览:291 次    日期:2024-05-04 04:30:25
【下载文档:  Struts过滤xss攻击的解决办法.txt 】


JSP Struts过滤xss攻击的解决办法
JSP Struts过滤xss攻击的解决办法
本方案采用struts2的拦截器过滤,将提交上来的参数转码来解决。
配置struts.xml
extends="struts-default, json-default">













...此处省略n个action


Java代码,拦截器实现类
import java.util.Map;
import org.apache.commons.lang3.StringEscapeUtils;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class XssInterceptor extends AbstractInterceptor{
@Override
public String intercept(ActionInvocation invocation) throws Exception {
// TODO Auto-generated method stub
ActionContext actionContext = invocation.getInvocationContext();
Map map = actionContext.getParameters();
for (Map.Entry entry : map.entrySet()) {
String value = ((String[])(entry.getValue()))[0];
entry.setValue(StringEscapeUtils.escapeHtml4(value));//将提交上来的字符串进行转码
//System.out.println((entry.getValue()));
}
return invocation.invoke();
}
}
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

相关内容