Time can take everything---road
Jetty is a lightweight servlet container, a bit like Tomcat, but it's easier to use than Tomcat.
Jetty Download Link: http://download.eclipse.org/jetty/
My development environment:
Operating system: UBuntu 14.04 LTS
Integration tools: Eclipse (Version:luna Service Release 1 (4.4.1) build id:20140925-1800)
Jetty Version: jetty-9.2.6
Let's go to the Hello World tour below.
Open Eclipse, right-click "New" in "Package Explorer"--> "Java Project", and in the pop-up box, fill in the project name "Jettywebapp" and "Finish". As shown in the picture is the construction of a good project
The jetty directory and the Webroot directory are built as shown in the picture.
The project was built, now the most important don't forget the package dependencies, find the following jar package in the downloaded Jetty package and import the package (referenced libraries).
Plus Javax.el-3.0.0.jar (screenshots cut it off)
The following is the source code
Start.java
Package start;
Import Org.eclipse.jetty.server.Server;
Import Org.eclipse.jetty.webapp.WebAppContext;
public class Start {public
static void Main (string[] args) {
Server server = new Server (8080);
Webappcontext context = new Webappcontext ();
Context.setcontextpath ("/jettywebapp");
Context.setdescriptor ("Webroot/web-inf/web.xml");
Context.setresourcebase ("WebRoot");
Context.setparentloaderpriority (true);
Server.sethandler (context);
try {
server.join ();
Server.start ();
} catch (Interruptedexception e) {
//TODO auto-generated catch block
e.printstacktrace ();
} catch ( Exception e) {
//TODO auto-generated catch block
e.printstacktrace ();
}
}
}
Xml
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns:xsi=
"Http://www.w3.org/2001/XMLSchema-instance" "Xmlns=" Http://java.sun.com/xml/ns/javaee "xmlns:web=" http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "xsi: schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version= " 3.0 ">
<display-name>jettyWebApp</display-name>
<welcome-file-list>
< welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
index.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding=" UTF-8 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
The above operation is completed then a complete Web project has been built, but also deployed almost, on the poor run. Open Start.java and right-click "Run as"--> "Java application". The results of the operation are as follows
The deployment is over.
Open the browser and enter in the Address bar: http://localhost:8080/jettyWebApp/