Jetty Embedded Services

Source: Internet
Author: User

pom.xml<properties><project.build.sourceencoding>utf-8</project.build.sourceencoding>< jetty.version>7.0.2.v20100331</jetty.version><slf4j.version>1.7.5</slf4j.version>< log4j.version>1.2.14</log4j.version><fastjson.version>1.2.20</fastjson.version></ properties><dependencies><!--built-in server configuration--><dependency><groupid> Org.eclipse.jetty.aggregate</groupid><artifactid>jetty-all-server</artifactid><version >${jetty.version}</version></dependency><dependency><groupid>org.slf4j</groupid ><artifactid>slf4j-log4j12</artifactid><version>${slf4j.version}</version><scope >provided</scope></dependency><dependency><groupId>log4j</groupId>< artifactid>log4j</artifactid><version>${log4j.version}</version><scope>provided< /scope></dependency><dependency><groupid>org.freemarker</groupid><artifactid>freemarker</artifactid><version>2.3.25- incubating </version><scope>provided</scope></dependency><dependency><groupid >com.alibaba</groupid><artifactid>fastjson</artifactid><version>${fastjson.version} </version><scope>provided</scope></dependency>

  

Code:

Package com.google.code.garbagecan.jettystudy.sample5;  Import Org.eclipse.jetty.server.Server;  Import Org.eclipse.jetty.servlet.ServletContextHandler;    Import Org.eclipse.jetty.servlet.ServletHolder; public class Servletcontextserver {public static void main (string[] args) throws Exception {Server server            = new Server (8080);          Servletcontexthandler context = new Servletcontexthandler (servletcontexthandler.sessions);          Context.setcontextpath ("/");            Server.sethandler (context);          Http://localhost:8080/hello Context.addservlet (New Servletholder (New HelloServlet ()), "/hello"); Http://localhost:8080/hello/kongxx Context.addservlet (New Servletholder (New HelloServlet ("Hello kongxx!")), "/            Hello/kongxx ");          Http://localhost:8080/goodbye Context.addservlet (New Servletholder (New Goodbyeservlet ()), "/goodbye"); Http://localhost:8080/goodbye/kongxx Context.addservlet (newServletholder (New Goodbyeservlet ("Goodbye kongxx!")), "/goodbye/kongxx");          Server.start ();      Server.join ();    }} package com.google.code.garbagecan.jettystudy.sample5;  Import java.io.IOException;  Import javax.servlet.ServletException;  Import Javax.servlet.http.HttpServlet;  Import Javax.servlet.http.HttpServletRequest;    Import Javax.servlet.http.HttpServletResponse;      public class HelloServlet extends HttpServlet {private static final long serialversionuid = 1L;        Private String msg = "Hello world!";      Public HelloServlet () {} public HelloServlet (String msg) {this.msg = msg; } protected void Doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexcepti          On {response.setcontenttype ("text/html");          Response.setstatus (HTTPSERVLETRESPONSE.SC_OK);          Response.getwriter (). println ("

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.