创建BaseController继承Jfinal自带的Controller,并供所有业务controller继承。
BaseController中重写Controller的getPara(String)方法
/**
* 重写getpara,处理XSS漏洞
*/
@Override
public String getPara(String name) {
// TODO Auto-generated method stub
String result=super.getPara(name);
if(result!=null) {
if(!result.equals(Jsoup.clean(result, Whitelist.none()))) {
throw new MyException("参数存在非法标签,请核对!");
}
}
return result;
}
其中Whitelist配置中,relaxed专注于script相关的脚本共计,none抵制所有html代码,其余配置根据需要查看Whitelist文档