자바 restful 서버 구축
2110 단어 javaee서비스 센터restrestful 서버
jar
asm-3.1.jar
jersey-client-1.17.1.jar
jersey-core-1.17.1.jar
jersey-server-1.17.1.jar
jersey-servlet-1.17.1.jar
jsr311-api-1.1.1.jar
web.xml
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">index.jspJersey REST Servicecom.sun.jersey.spi.container.servlet.ServletContainercom.sun.jersey.config.property.packagescom.control1Jersey REST Service/rest/*
코드
package com.control;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import net.sf.json.JSONObject;
/**
* http://www.importnew.com/7336.html
* @author jsonv_000
*
*/
// @Path 。
// URI 。
@Path("UserInfoService")
public class UserInfo {
// @GET HTTP GET
@GET
// @Path 。 URI 。
@Path("/name/{i}")
// @Produces 。
@Produces(MediaType.TEXT_HTML)
// @Produces({"application/xml", "application/json"})
// @PathParam @Path URI 。
public String userName(@PathParam("i") String i) {
// JSONObject jsonObject =new JSONObject();
// String name = i;
// jsonObject.put("code", ""+name);
// //return "" + "" + name + " " + " ";
return "{'invokemethod':'sucess','postmethod','true'}";
// return jsonObject.toString();
}
@GET
@Path("/age/{j}")
@Produces(MediaType.TEXT_XML)
public String userAge(@PathParam("j") int j) {
int age = j;
return "" + "" + age + " " + " ";
}
}
방문:http://localhost:8080/restful/rest/UserInfoService/name/Pavithrajiaxi
표시:
{'invokemethod':'sucess','postmethod','true'}
참고 자료
http://www.importnew.com/7336.html
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Error building SqlSession.mybatis의 학습을 진행할 때 컨트롤러에서 위의 오류를 보고했습니다. 분명히 한 걸음 한 걸음 왔는데 어떻게 이런 오류를 보고할 수 있습니까? 인터넷에서 찾아봐도 좋은 답을 찾지 못해서 한 걸음 인쇄해서 문제를 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.