Getting started with Jetty

Source: Internet
Author: User

This is a javaproject

First, loginservlet. Java to be included in jetty Management

Package COM. jadyer. servlet; import Java. io. ioexception; import Java. io. printwriter; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; public class loginservlet extends httpservlet {Private Static final long serialversionuid = response; @ overrideprotected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {system. out. println ("received request parameter [" + request. getparameter ("username") + "]"); response. setcontenttype ("text/html; charset = UTF-8"); printwriter out = response. getwriter (); out. print ("<H2> This Is My embedded jetty test result </H2>"); out. flush (); out. close ();}}

The following is the userservlet. Java to be included in jetty management.

Package COM. jadyer. servlet; import Java. io. ioexception; import Java. io. printwriter; import javax. servlet. servletexception; import javax. servlet. HTTP. httpservlet; import javax. servlet. HTTP. httpservletrequest; import javax. servlet. HTTP. httpservletresponse; public class userservlet extends httpservlet {Private Static final long serialversionuid = response; @ overrideprotected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {System. out. println ("received request parameter [" + request. getparameter ("username") + "]"); response. setcontenttype ("text/html; charset = UTF-8"); printwriter out = response. getwriter (); out. print ("<H2> This Is My embedded jetty test result --> the user successfully accessed the servlet </H2>"); out. flush (); out. close ();}}

Finally, I wrote my own jetty startup class myserver. Java (including the simple usage of jetty embedded)

Package COM. jadyer. jetty; import Java. util. hashmap; import Java. util. map; import javax. servlet. servlet; import Org. eclipse. jetty. server. server; import Org. eclipse. jetty. servlet. servletcontexthandler; import Org. eclipse. jetty. webapp. webappcontext; import COM. jadyer. servlet. loginservlet; import COM. jadyer. servlet. userservlet;/*** @ see ------------------------------------------------------------------------- ----------------------------------- * @ See jetty Introduction * @ see Jetty is an embedded web server * @ see jetty Official Website: http://www.eclipse.org/jetty/ * @ see jetty download: http://download.eclipse.org/jetty/ * @ see dependencies * @ see jetty compared with Tomcat (taken from the network) * @ see jetty architecture is simpler than tomcat, it is implemented based on handler, it can be extended through handler * @ see Tomcat's architecture is based on In the container design, you need to understand the overall design results of Tomcat during Tomcat extension, so it is not easy to extend * @ see -------------------------------------------------------------------------------------------------------------- * @ see Jetty to use * @ see 0) version selection: because jetty9425jdk7is supported, we use jetty-distribution-8.1.10.v20130312.zip * @ see 1) to modify the port: modify \ jetty_home \ etc \ jetty. XML 40th line default = "8080" * @ see 2) Non-embedded project release (two methods are available) * @ see non-embedded Startup Mode: execute this command under the command line --> D: \ develop \ jetty-distributi On-8.1.10.v20130312> JAVA-jar start. jar * @ see first: compress the project into a war package and place it under \ jetty_home \ webapps \. The access address is http: // 127.0.0.1: 8080/warname (the war name is case-insensitive) * @ see Method 2: similar to Tomcat's <context Path = "" docbase = ""> method, add an arbitrary XML file * @ see and javadoc in the \ jetty_home \ contexts \ directory. the XML format is the same. Modify the following two items: * @ See <set name = "contextpath">/testbbb </set> * @ See <set name = "resourcebase"> F: /tool/code/javase/loginmanager/webroot </set> * @ See 3) embedded project release * @ see is to add the jar provided by Jetty to the project (which can be a Java project or a Web project), and then write the program through a main () start Jetty. The jar used is as follows * @ see lib directory in jetty_home and JSP directory in Lib. Add the jar files in these two directories to the project (if the JSP page is not involved, you do not need the jar in the JSP directory.) * For details about @ see, see startforservlet () and startforwebapp () methods here. * @ See example * @ create Jul 5, 2013 12:54:24 * @ author Xuan Yu 

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.