No. 03 article. Standard Web project Jetty9 embedded API simple Startup

Source: Internet
Author: User

 

All along, want to change some of the things that you have been accustomed to before.

To a certain age, you have to learn to be quiet, every word should be useful, there is weight.

Xi Nu not shape in color, big things indifferent, have their own bottom line.

-- Mr. Fat

yesterday, simply said about the configuration of the Jetty9, everyone in the use of the Maven era, and fat mister to get the standard Web project Embedded server , This is for my students to prepare, if there is this aspect of the Spit groove please bypass!

The First step is to build a Dynamic Web project in sts[or Eclipse], for everyone should be a small case, where I use the login example of the Springmvc+mybatis project that was done in the previous lesson.

 

 

The second step to introduce the jar needed for Jetty9, don't think about optimization? What is unreasonable? We're playing violence The result is what we want!

Find jetty yesterday our unzip directory, the Lib folder, select all the jar files I marked, Placed under the Web-inf/lib folder [but this feeling, the whole project jar package suddenly more]
 


I have created a new folder under the Lib folder jetty, but if so, you need manual Add Bulid path action




   

Step three , using the API provided by jetty to make calls,

If you have questions, you can access http://www.eclipse.org/jetty/documentation/current/embedding-jetty.html

To view the Help documentation, the source code is :

Import Org.eclipse.jetty.server.Server;

Import Org.eclipse.jetty.webapp.WebAppContext;

Public class jettylauncher {

Public staticvoid main (string[] args) {

server Server = new Server (8002); Set the port number

Try {

Webappcontext Context = new webappcontext ();

context. Setcontextpath ("/mvc"); Access Path

context. Setresourcebase ("e:/java-workspace/ xiangyun 37MSS stage /mytest/ WebContent "); // Path

context. SetDescriptor ("e:/java-workspace/ xiangyun 37MSS stage /mytest/ Webcontent/web.xml "); // Read the Web. xml file

Server. SetHandler (context);

Server. Start ();

Server. Join ();

} catch (Exception e) {

E. Printstacktrace ();

}

}

}

 

Fourth step , run the main method, execute Java application, access in the address bar

http://127.0.0.1:8002/mvc/index.jsp page

 

However, when we log in, the page shows that the path is not found Sys/login , reported error not FOUND 404, which is why?
After a careful look at the console, feeling missing something!
I hope you can make the same mistake, if you use the MyEclipse IDE's kids boots, this problem should not occur because our Java file compiles the file path under the Bulid/classes file instead of under the Web-inf/classes folder , because I created a new classes folder in Web-inf , modify the path of the compilation, Hey, you know?

Fifth Step , modify the Java file compilation path

What else can we do with this setting, to set up a virtual directory for Tomcat, please refer to the blog post:

Http://www.cnblogs.com/pangxiansheng/p/4436900.html

Sixth Step , test again, you are done, whoa, ka!

Plan: For different ways of starting and distributed, in a simple study

Mr. Fat's

I feel this article is helpful to you, please click
recommended ↓↓↓↓↓↓↓↓↓↓
your support is my biggest motivation ,
This information is recommended to Sihai, " " all of You,
I hope you work well, no matter when and where,
can help you are Mr. Fat's honor!
 

Please reward, test it

 

No. 03 article. Standard Web project Jetty9 embedded API simple Startup

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.