springmvc jackson 一直提示uri非法字符

09-10

前端: $(document).ready(function(){ $("#login").click(function(){ var username= document.getElementById("username").value; var password = document.getElementById("password").value; /*alert(username+" "+password);*/ var jo ={"username":"wushangkang"}; var json = JSON.stringify(jo); $.ajax({ type:"get", url:"http://localhost:8080/springmvc2/JsonGet", async:true, data:JSON.stringify(jo), dataType:"application/json", success:function(datas){ alert(datas); }, error:function(){ alert("登录出错"); } }); }); }); springmvc配置文件: <context:component-scan base-package="com.controller" /> <mvc:annotation-driven /> <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="mappingJacksonHttpMessageConverter" /> </list> </property> </bean> <bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> <value>application/json;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> </list> </property> </bean> jackson jar包 jackson-core-2.2.3.jar jackson-databind-2.2.3.jar jackson-annotations-2.2.3.jar 代码: @Controller public class JsonController { @RequestMapping(value="/JsonGet",method=RequestMethod.GET) @ResponseBody public String getJson(@RequestBody User user){ System.out.println("------------------begin---------------"); System.out.println(user.getUsername()); System.out.println("------------------end------------------"); return "success"; } } 错误提示: 严重: Servlet.service() for servlet [springmvc] in context with path [/springmvc2] threw exception [Request processing failed; nested exception is java.lang.Illeg alStateException: Could not get HttpServletRequest URI: Illegal character in que ry at index 41: http://localhost:8080/springmvc2/JsonGet?{%22username%22:%22wush angkang%22}] with root cause 第41位置应该是大括号,双引号被转译%22,这大概是编码问题,这是用火狐才这样,用IE就没事,不过还是错误 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: Age of Ai 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览

应支付19.90元
点击重新获取
扫码支付

支付成功即可阅读