2 k1210228840 k1210228840 于 2016.09.10 18:36 提问

springmvc jackson 一直提示uri非法字符 4C

前端:
$(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个回答

k1210228840
k1210228840   2016.09.11 09:39

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

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!