现在的位置: 首页 > 综合 > 正文

restful-xml

2013年05月22日 ⁄ 综合 ⁄ 共 865字 ⁄ 字号 评论关闭

@Path("student")
public class StudentXMLService {

// <student>
// <name>xiewenbo</name>
// <number>13061012</number>
// </student>
@GET
@Produces(MediaType.APPLICATION_XML)
public Student getStudentXML(){

Student student = new Student("xiewenbo","13061012");
return student;
}

}

public class StudentTest {

public static void main(String[] args) throws IOException {
        URI ServerURI=UriBuilder.fromUri("http://localhost/").port(9998).build();
    startServer(ServerURI);
        System.out.println("服务已启动,请访问:"+ServerURI);
    }    

    protected static SelectorThread startServer(URI serverURI) throws IOException {
        final Map<String, String> initParams = new HashMap<String, String>();
        initParams.put("com.sun.jersey.config.property.packages","com.ws.service.xml");
        System.out.println("Grizzly 启动中...");
        SelectorThread threadSelector = GrizzlyWebContainerFactory.create(serverURI, initParams);     
        return threadSelector;
    }  

}

抱歉!评论已关闭.