There weren't many ways to implement it without using maven or gradle, so I'll write it.
Create a dynamic web project in Eclipse Create a package [com.sample.api] and a class [SampleApi.java] under it.
Create [web.xml] in WebContent / WEB-INF and copy the following.
filename.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>jersey-app</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.api.sample</param-value><!--package name-->
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>jersey-app</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
Edit the first created ApiSample.java below.
ApiSample.java
package com.api.sample;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("/Sample")
public class ApiSample {
@Path("/hello")
@GET
@Produces(MediaType.TEXT_HTML + "; charset=UTF-8")
public String hello(@QueryParam("name") final String name){
return "Hello!"+name+"Mr.";
}
}
http://localhost:8080/プロジェクト名/api/Sample/hello
Results Hello! Null.
Is displayed, it is OK. Also, http: // localhost: 8080 / project name / api / Sample / hello? name = Yamada If you enter
Hello! Mr. Yamada.
Should be displayed.
Recommended Posts