//java pojo @XmlRootElement public class User { private String username; private String password; ...... } // 注意 如果 User 没有加 XmlRootElement 注解: 则会抛出一个 Exception in thread "main" com.sun.jersey.api.client.UniformInterfaceException: GET http://localhost:8080/jersey/services/getUser returned a response status of 500 /** * 通过 http-Get 方式访问 */ @Path("/getUser") public class GetUser { // 请求xml Json @GET @Produces({MediaType.APPLICATION_XML,MediaType.APPLICATION_JSON}) public User sayHello() throws Exception{ User user = new User(); user.setUsername("涛哥"); return user; } // 请求 纯文本 @GET @Produces(MediaType.TEXT_XML) public User getUser() throws Exception{ User user = new User(); user.setUsername("taoge"); user.setPassword("779899"); return user; } } // 测试 ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); // Get XML System.out.println(service.path("services").path("getUser").accept( MediaType.APPLICATION_XML).get(String.class));