cxshun 2012-09-25 11:30
浏览 221
已采纳

spring responseBody返回xml在IE下有问题

我使用spring的responseBody返回xml,在chrome,firefox下均没问题,但在IE下会出现应用程序出错的问题。
我的代码如下:
UserController:
[code="java"]
package com.spring;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

@RequestMapping("/user")
public @ResponseBody User getUser(){
    User user = new User();
    user.setName("shun");
    user.setPassword("123123");
    return user;
}

}

@XmlRootElement(name="user")
class User {
private String name;
private String password;
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

[/code]

web.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>


spring
org.springframework.web.servlet.DispatcherServlet
1


spring
/


index.jsp


[/code]

spring-servlet.xml
[code="xml"]
<?xml version="1.0" encoding="UTF-8"?>
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.spring" />

<bean
    class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="mediaTypes">
        <map>
            <entry key="xml" value="application/xml" />
            <entry key="json" value="application/json" />
            <entry key="jsonp" value="application/javascript" />
        </map>
    </property>
    <property name="defaultContentType" value="text/html" />
    <property name="ignoreAcceptHeader" value="true" />
    <property name="favorPathExtension" value="true" />
    <property name="favorParameter" value="true" />
    <property name="parameterName" value="return_fmt"></property>
    <property name="viewResolvers">
        <list>
            <bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />
        </list>
    </property>
    <property name="defaultViews">
        <list>
            <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                <property name="marshaller">
                    <ref bean="castorMarshaller"/>
                </property>
            </bean>
            <bean
                class="org.springframework.web.servlet.view.json.MappingJacksonJsonView" />
        </list>
    </property>
</bean>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" />

[/code]

当我用其他浏览器的时候,返回正常,如下:

[img]http://dl.iteye.com/upload/attachment/0074/3130/9124add8-e4e1-31a8-b13b-f6ec0aaf059c.png[/img]

而用IE的时候,返回如下:

[img]http://dl.iteye.com/upload/attachment/0074/3125/d7768747-ca04-3d0d-8916-905b2da1ddec.png[/img]

我在项目中有打印执行方法的次数,发现在IE中会进行两次访问,之后就出现如图的错误,猜想可能是进行了循环的访问。

有哪位朋友遇到过这样的问题,或知道出错在哪里,忘告知,多谢。

  • 写回答

2条回答 默认 最新

  • jinnianshilongnian 2012-09-25 13:21
    关注

    这估计是浏览器问题 跟你程序无关

    你到chrome下debug看戏 response header 发上来

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改