当前位置: 代码迷 >> Eclipse >> org.eclipse.jetty.util.$NotUtf8Exception: Not valid UTF8! byte Dc in state 二
  详细解决方案

org.eclipse.jetty.util.$NotUtf8Exception: Not valid UTF8! byte Dc in state 二

热度:1540   发布时间:2016-04-23 00:57:24.0
org.eclipse.jetty.util.$NotUtf8Exception: Not valid UTF8! byte Dc in state 2

2014-02-09 23:44:54.705:WARN:oejs.ServletHandler:/mideaAdmin/ajaxAddUser.midea
org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! byte Dc in state 2
?at org.eclipse.jetty.util.Utf8Appendable.appendByte(Utf8Appendable.java:168)
?at org.eclipse.jetty.util.Utf8Appendable.append(Utf8Appendable.java:107)
?at org.eclipse.jetty.http.HttpURI.toUtf8String(HttpURI.java:491)
?at org.eclipse.jetty.http.HttpURI.toString(HttpURI.java:665)
?at java.lang.String.valueOf(String.java:2826)
?at java.lang.StringBuilder.append(StringBuilder.java:115)
?at org.eclipse.jetty.server.Request.toString(Request.java:1927)
?at java.lang.String.valueOf(String.java:2826)
?at java.lang.StringBuilder.append(StringBuilder.java:115)
?at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:640)
?at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
?at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
?at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
?at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:594)
?at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1365)
?at com.hailong.midea.web.filter.SessionFilter.doFilterInternal(SessionFilter.java:80)
?at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
?at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
?at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
?at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
?at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1336)
?at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:483)
?at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
?at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:521)
?at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:233)
?at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
?at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:412)
?at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
?at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
?at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
?at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
?at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
?at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
?at org.eclipse.jetty.server.Server.handle(Server.java:351)
?at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:451)
?at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:916)
?at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:634)
?at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:230)
?at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:76)
?at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:609)
?at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:45)
?at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:599)
?at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:534)
?at java.lang.Thread.run(Thread.java:6

?

? //JSP前端提交Ajax请求;
?jQuery.ajax({
??type: "POST",
??url: url+"&reqtime="+new Date().getTime(),
??contentType:"text/html;charset=UTF-8",
??success:function(msg){
???alert("返回结果:"+msg);
???if(msg != null ){
????if(msg == "success"){
?????//跳转用户管理页面;
?????window.location = contextPath+"/userManagement.midea";
????}else{
?????jQuery("#displayResultId").slideDown(200);
?????jQuery("#displayResultId > #titleId").html("温馨提示:");
?????jQuery("#displayResultId > #contentId").html("抱歉,添加用户失败!请输入用户信息,重试!");
?????reset();
?????jQuery("#userId").focus();
????}
???}
??}
?});
?

服务器端:

?@RequestMapping(value="/addUser")
public void addUser(UserEntity userEntity,HttpServletRequest request,HttpServletResponse response){
PrintWriter out = null;
try {
//给密码加密;
userEntity.setPassword(MD5EncryptUtil.encryptMD5Code(userEntity.getPassword()));
//执行用户添加操作;
boolean bol = userManager.addUser(userEntity);
logger.info("添加用户信息:[UserController->addUser] [添加结果]:"+bol);
out = response.getWriter();
out.print(bol?"success":"failure");
out.flush();
} catch (MideaException e) {
logger.error("添加用户信息报错-位置:[UserController->addUser]", e);
} catch (IOException e) {
logger.error("获取response.getWriter报IO Exception 位置:[UserController->addUser]", e);
}finally{
if(out !=null){
out.close();
}
}
}


?解决方案:
?原因是因为前端jsp使用ajax提交到服务器端 ,后台contorller里面使用UserEntity userEntity接收会存在转换问题 ,所以,如果使用ajax请求服务器,则不能在addUser方法中存在实体参数。

如果是Post或者Get请求则没有问题。

  相关解决方案