Announcement Announcement Module
Collapse
No announcement yet.
@ResponseBody return xml in IE failed. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ResponseBody return xml in IE failed.

    I'm trying to use responseBody annotation to return xml in controller.Every browser works fine except IE(I'm using IE 9 in windows 7 x64). I found that it will request several times and then failed in request.Hope some of you haved encounter this and offer some help.
    My code as followed:
    UserController.java.This is just a simple controller,returning an object that represent User.
    Code:
    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;
    	}
    }
    web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
      <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
      </servlet-mapping>
      <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
    </web-app>
    I used spring-servlet.xml as my spring configuration file.
    As following:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    	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" />
    	
    </beans>
    By the way, my spring version is 3.1.0.And I also used 3.0.7 for test,just the same result.
    After I started my project,I use chrome,firefox to visit it ,everything is fine.But When I try visiting it in IE 9,it shows me this result.
    Attachment

    Is anyone can tell me what happened?Thank you!
    Attached Files
    Last edited by cxshun; Sep 24th, 2012, 11:25 PM.
Working...
X