我使用以下技术:Glassfish,泽西岛 我在IntelliJ中获得了以下项目结构:
beat_api
->.idea
->lib
->out
->src
->ApplicationController.java
->Beat.java
->web
->WEB-INF
web.xml
->index.jsp (want to convert that to HTML though, no idea how .jsp works)
我有以下问题:
Beat.java
import javax.ws.rs.*;
// The Java class will be hosted at the URI path "/beats"
@Path("/beats")
public class Beat {
// The Java method will process HTTP GET requests
// The Java method will produce content identified by the MIME Media type "text/plain"
@GET
@Produces("text/plain")
@Path("/show")
public String retrieveBeat() {
return "hello";
}
// The Java method will process HTTP GET requests
// The Java method will produce content identified by the MIME Media type "text/plain"
@POST
@Consumes("text/plain")
@Path("create/{beatname}/{beatbpm}/{beatkey}")
public void createBeat(@PathParam("beatname") String beatname,
@PathParam("beatbpm") int beatbpm,
@PathParam("beatkey") String beatkey) {
}
}
ApplicationController.java
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
//Defines the base URI for all resource URIs.
@ApplicationPath("/")
//The java class declares root resource and provider classes
public class ApplicationController extends Application{
//The method returns a non-empty collection with classes,
// that must be included in the published JAX-RS application
@Override
public Set<Class<?>> getClasses() {
HashSet h = new HashSet<Class<?>>();
h.add( Beat.class );
return h;
}
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
</web-app>