Create a dynamic Web Project in eclipse

Source: Internet
Author: User

Create a good project directory as follows:

At first I now created a test.jsp in Web-inf but found Tomcat above run error

Cause of Error:

In Eclipse's Package explorer, check where the files are stored. Since Meta-inf

The contents of the Web-inf folder cannot be released externally, so if you reference a file with these two directories, it is definitely not allowed.

Workaround: Drag test.jsp from Web-inf to WebContent

Run again:

Ii. Creating a Servlet instance

The code for HelloServlet is as follows:

Package com.chenjn.www;

Import java.io.IOException;
Import javax.servlet.ServletException;
Import Javax.servlet.annotation.WebServlet;
Import Javax.servlet.http.HttpServlet;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;

/**
* Servlet Implementation Class HelloServlet
*/
@WebServlet ("/helloservlet")
public class HelloServlet extends HttpServlet {
Private static final long serialversionuid = 1L;

/**
* @see Httpservlet#httpservlet ()
*/
Public HelloServlet () {
Super ();
TODO auto-generated Constructor stub
}

/**
* @see Httpservlet#doget (httpservletrequest request, httpservletresponse response)
*/
protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
TODO auto-generated Method Stub
Response.setcharacterencoding ("GBK");
Response.getwriter (). Write ("Hello world! ");
}

/**
* @see Httpservlet#dopost (httpservletrequest request, httpservletresponse response)
*/
protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
Doget (Request,response);
TODO auto-generated Method Stub
}

}

Restarting the Tomcat server runs the following results:

Create a dynamic Web Project in eclipse

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.