jettey内嵌启动app

作者:美狮美高梅官方网站

新美高梅网站美狮美高梅官方网站 ,jettey内嵌启动app:

public class JettyServer { private void start() throws Exception { int port = 8080; Server server = new Server; ServletContextHandler context = new ServletContextHandler( ServletContextHandler.SESSIONS); context.setContextPath; server.setHandler; ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter( "com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.gmobile.api"); //包名为jersey的路由Resource所在目录,如下代码展示 context.addServlet; server.start(); } public void stop() throws Exception { } public static void main(String[] args) throws Exception { JettyServer server = new JettyServer(); server.start(); }}
此处是jersey的基于注解的路由分发类:
@Pathpublic class WelcomeResource { @GET @Produces(MediaType.TEXT_PLAIN) @Path public Viewable sayHello() throws IOException { return new Viewable("/index.jsp", this); } @GET @Path public String index() { return "hello world!!!"; } @POST @Path public String login() { return "login"; }}

本文由美狮美高梅官方网站发布,转载请注明来源

关键词: