Modify servlet new template __java in Eclipse for Java EE

Source: Internet
Author: User

When you use Eclipse for Web development, there are a lot of annotations when creating a servlet, which is very, very concise, and you can write the corresponding template to create the servlet yourself.
Operation diagram

1. First find the window on the menu bar and click the dropdown column, select the Preferences option in the dropdown column to jump out of the following figure

2. Find the Java Column Point open-> find the editor point open-> Find one of the templates click appear as shown above

Click on the New button on the right to appear a window similar to the following figure

3. Type the above content in name and description on the interface, and enter your own servlet template in the pattern below

My own template is as follows

Package ${enclosing_package};
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; /** * @author ${user} e-mail:example@aliyun.com * @version creation time: ${date} ${time} * ${tags} */@WebServlet ("/${primar Y_type_name} ") public class ${primary_type_name} extends HttpServlet {private static final long Serialversionuid = 1

    L
        protected void doget (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {
        Request.setcharacterencoding ("UTF-8");
        Response.setcharacterencoding ("UTF-8"); Response.setcontenttype ("text/html;
    Charset=utf-8 "); } protected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, Ioexceptio
    n {doget (request, response);

 }

}

4. Click on the bottom of the OK button, and then back to the Java EE view a new servlet file, use the shortcut key CTRL + A full selection code, type the word "servlet", the code automatically prompts, and then click the Enter button to get their own code.

Note: When I run with the other blogs I always report 404 errors, probably because of my personal reasons, later I used the annotation class, the test can run normally. Additional configuration is available in Web.xml if necessary

Related Article

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.