I write a jettyserver.java
as start service,here is the code,
public class jettyserver {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
Map<String, String> parameterMap = new HashMap<String, String>();
parameterMap.put("jersey.config.server.provider.packages", "com.heu.cs.mavenproject3");
servletHolder.setInitParameters(parameterMap);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/jettyproject/*");
context.addServlet(servletHolder, "/*");
server.setHandler(context);
server.start();
server.join();
}
}
And I write a demo.java
as a test demo,
@Path("/demo")
public class demo {
@GET
@Produces({"text/html"})
public String index(){
return "OK";
}
}
and then i run jettyserver.java
,I got OK like:
we can see OK,that's right but wen I enter localhost:8080/jettyproject/index.html or localhost:8080/index.html in the browser, I got a 404 error like this:
what should I do ? What'wrong with the code????