和二不要调皮 2016-09-10 10:36 采纳率: 42.9%
浏览 1299
已结题

springmvc jackson 一直提示uri非法字符

前端:
$(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就没事,不过还是错误

  • 写回答

1条回答

  • 和二不要调皮 2016-09-11 01:39
    关注

    顶起!!!!!!!!!!!!!!!!!!

    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题