package tao.jersey; import java.io.IOException; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import com.sun.jersey.api.container.httpserver.HttpServerFactory; import com.sun.net.httpserver.HttpServer; // 指定URI @Path("/helloworld") public class HelloWorld { @GET // 处理HTTP的GET请求 @Produces("text/plain") // 处理请求反馈的内容格式为"text/plain" public String getClientMessage(){ return "hello world 我爱你"; } public static void main(String[] args) throws Throwable, IOException { // 创建RESTful Webservice 服务 HttpServer server = HttpServerFactory.create("http://127.0.0.1:8080/"); // 启动服务 , 这会导致新开一个线程 server.start(); System.out.println("RESTful WebServic服务已经启动..."); System.out.println("服务访问地址:http://127.0.0.1:8080/helloworld"); } } 然后打开 浏览器 输入:http://127.0.0.1:8080/helloworld 然后看看浏览器 显示输出结果: ok 有一个问题没解决: 乱码 。。。。。。。。。。。。。 待续。。。。。。。。。。。。 参考:http://lavasoft.blog.51cto.com/62575/229206