java - Spring and XML responce -
i have problem spring mvc , xml response via @responsebody. here web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <filter> <filter-name>formencodingsetterfilter</filter-name> <filter-class>ua.yura.controllers.encodingfilter.bkifilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>formencodingsetterfilter</filter-name> <url-pattern>*.htm</url-pattern> </filter-mapping> <servlet> <servlet-name>bki</servlet-name> <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>bki</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
this bki-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:util="http://www.springframework.org/schema/util" xsi:schemalocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd"> <context:component-scan base-package="ua.yura.controllers"/> <mvc:annotation-driven/> <mvc:resources mapping="/img/**" location="/imgs/"/>
and xmlcontroller class:
@controller @requestmapping( value = "/xml" ) public class xmlcontroller { @requestmapping( value = "/test.htm", headers = "accept=application/xml") @responsebody public client test() { system.out.println("aaaa"); client client = new client(-1,"1","1","1","1","1","1","1"); return client; } }
class client annotation @xmlroot , @xmlelement. in java application want send request dispatcher servlet , xml data client object. tried next:
url = new url("http://localhost:8080/xml/test.htm"); httpurlconnection yc = (httpurlconnection)my.openconnection(); yc.addrequestproperty("accept", "application/xml"); //yc.setrequestmethod("get"); bufferedreader in = new bufferedreader( new inputstreamreader( yc.getinputstream() )); string inputline; while( (inputline = in.readline()) != null) system.out.println( inputline); in.close();
but every time error 406, web browser show next message: the resource identified request capable of generating responses characteristics not acceptable according request "accept" headers. can errors.
Comments
Post a Comment