过滤器Filter获取request信息之后报错
在过滤器中
HttpServletRequest httpservletrequest = (HttpServletRequest) request;
javax.servlet.ServletInputStream servletinputstream = httpservletrequest.getInputStream();
StringBuffer stringbuffer = new StringBuffer();
byte abyte0[] = new byte[4096];
int i;
if(null!=servletinputstream){
while((i = servletinputstream.read(abyte0)) != -1){
stringbuffer.append(new String(abyte0, 0, i));
}
}
只要执行了servletinputstream.read(abyte0) 之后
再执行filterChain.doFilter(request, response);后就会报错:
A JSONObject text must begin with '{' at character 0 Filter Java JsonObject request --------------------编程问答-------------------- 贴完整的代码。
A JSONObject text must begin with '{' at character 0:此处为字符串转Json对象错误,即Json字符串对象必须以{ 开始 --------------------编程问答--------------------
这个是JAVA代码 ,是个过滤器public class UserOperFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) throws IOException, ServletException {
HttpServletRequest httpservletrequest = (HttpServletRequest) request;
javax.servlet.ServletInputStream servletinputstream = httpservletrequest.getInputStream();
System.out.println(ToStringBuilder.reflectionToString(servletinputstream,null,true));
StringBuffer stringbuffer = new StringBuffer();
byte abyte0[] = new byte[4096];
int i;
if(null!=servletinputstream){
while((i = servletinputstream.read(abyte0)) != -1){
stringbuffer.append(new String(abyte0, 0, i));
}
}
filterChain.doFilter(request, response);
很正常的一个过滤器,写这个过滤器的目的就是为了得到 request请求对应的类和方法
比如点击查询按钮对应的是后台的ActionA.queryMethod() 就是想取得ActionA 和 queryMethod
补充:Java , Web 开发