其他分享
首页 > 其他分享> > 用Jersey构建RESTful服务

用Jersey构建RESTful服务

作者:互联网

一、环境

二、流程

package com.waylau.rest.resources; 
 import javax.ws.rs.GET; 
 import javax.ws.rs.Path; 
 import javax.ws.rs.Produces; 
 import javax.ws.rs.PathParam; 
 import javax.ws.rs.core.MediaType; 
 @Path("/hello") 
 public class HelloResource { 
 @GET @Produces(MediaType.TEXT_PLAIN) 
 public String sayHello() { 
 return "Hello World!" ; 
 }

 @GET @Path("/{param}") 
 @Produces("text/plain;charset=UTF-8") 
 public String sayHelloToUTF8(@PathParam("param") String username) 
 { 
 return "Hello " + username; 
 }

 }
<servlet> <servlet-name>Way REST Service</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>com.waylau.rest.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Way REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> 

http://localhost:8089/RestDemo/rest/hello/Way%E4%BD%A0%E5%A5%BD%E5%90%97,输出Hello Way你好吗

 

标签:ws,rs,rest,Hello,构建,import,RESTful,javax,Jersey
来源: https://www.cnblogs.com/tiancai/p/14285406.html