zili_zq
zili_zq
2018-11-24 13:38

java filter 字符过滤功能:java.lang.NoClassDefFoundError.

40
  • exception
  • filter
  • java
  • servlet

出现的问题:

javax.servlet.ServletException: Servlet execution threw an exception
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cc.openhome.web.EscapeFilter.doFilter(EscapeFilter.java:16)
Root Cause

java.lang.NoClassDefFoundError: Could not initialize class org.apache.commons.text.StringEscapeUtils
cc.openhome.web.EscapeWrapper.getParameter(EscapeWrapper.java:15)
cc.openhome.controller.Login.doPost(Login.java:30)
javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
cc.openhome.web.EscapeFilter.doFilter(EscapeFilter.java:16)

字符过滤代码:
package cc.openhome.web;

import org.apache.commons.text.StringEscapeUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class EscapeWrapper extends HttpServletRequestWrapper {
public EscapeWrapper(HttpServletRequest req){
super(req);
}

public String getParameter(String name){
    String value = getRequest().getParameter(name);
    return StringEscapeUtils.escapeHtml4(value);
}

}

使用的是;
commons-text-1.6.jar
其他版本:
commons-text-1.4.jar
commons-text-1.5.jar
都实验过均出现这个问题
编译可以通过,在用户登录后出现上面错误.
求大神指点!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答