有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpring:Http406此请求标识的资源只能

我使用Spring4。0.0、SpringMVC和我有jackson-core-asl-1.9.13.jar,jackson-mapper-asl-1.9.13.jar

The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers.

我的控制器

@RequestMapping(value="login.do",method= RequestMethod.POST)
@ResponseBody
public ServerResponse<User> login(String username, String password, HttpSession session){
    ServerResponse<User> response = iUserService.login(username,password);
    if(response.isSuccess()){
        session.setAttribute(Const.CURRENT_USER,response.getData());
    }
    return response;
}

我的调度器servlet。xml已经有了内容。这些是文件的一部分

 xsi:schemaLocation="
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

 <mvc:annotation-driven>
    <mvc:message-converters>
        <bean class="org.springframework.http.converter.StringHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>text/plain;charset=UTF-8</value>
                    <value>text/html;charset=UTF-8</value>
                </list>
            </property>
        </bean>
        <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
            <property name="supportedMediaTypes">
                <list>
                    <value>application/json;charset=UTF-8</value>
                </list>
            </property>
        </bean>
    </mvc:message-converters>
</mvc:annotation-driven>

但我使用调试它。没关系。 enter image description here

然后我使用网络,它不工作。 enter image description here


共 (1) 个答案

  1. # 1 楼答案

    根据你的调试图片,你需要User,我猜json

    只需返回User而不是ServerResponse<User>