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