Run helloworld Jetty

Source: Internet
Author: User

Jetty is a lightweight embedded servlet container. It is easy to start and run. There are several steps to run the jetty container in Eclipse,

1. Create a common Java Project
Jar is added to make the project support JSP files)
3. Create a web directory. A folder named web contains a WEB-INF folder and a web. xml file.
The content of the web. xml file is as follows:
<?xml version="1.0" encoding="UTF-8"?><web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>

 


4. Compile a Java code as follows:
Java code
 
Package test; import Org. mortbay. jetty. connector; import Org. mortbay. jetty. server; import Org. mortbay. jetty. NIO. selectchannelconnector; import Org. mortbay. jetty. webapp. webappcontext; public class bootstart {public static void main (string [] ARGs) throws exception {Server service = new server (); connector conne= new selectchannelconne (); // set the port connector. setport (8080); // set the host address connector. sethost ("127.0.0.1"); service. setconnectors (new connector [] {connector}); // set the root path webappcontext context = new webappcontext ("Web", "/Web"); service. addhandler (context); service. setstopatshutdown (true); service. setsendserverversion (true); // start the service. start (); service. join ();}}

 


5. Test the JSP file index. jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

 


6. Run the main method and test the connection http: // 127.0.0.1: 8080/Web

Run helloworld Jetty

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.