Modify the MyEclipse default servlet code template __myeclipse

Source: Internet
Author: User

To modify the default template code for a servlet

When you use MyEclipse to create a servlet, the servlet code that is generated from the default servlet template is as follows:
  

1 package gacl.servlet.study;
 2 3 Import java.io.IOException;
 4 Import Java.io.PrintWriter;
 5 6 Import Javax.servlet.ServletException;
 7 Import Javax.servlet.http.HttpServlet;
 8 Import Javax.servlet.http.HttpServletRequest;
9 Import Javax.servlet.http.HttpServletResponse; The public class Servletdefaulttemplatecode extends HttpServlet {/** * the Doget Let.
<br> * This is called when a form has it tag value method equals to get. * @param request the request send by the client to the server * @param response the response SE  nd by the "server to" @throws servletexception if an error occurred * @throws IOException if             Error occurred/* public void doget (HttpServletRequest request, httpservletresponse response) 24 Throws Servletexception, IOException {response.setcontenttype ("text/html"); PrintWriter oUT = Response.getwriter (); Out.println ("<!
DOCTYPE HTML public \-//w3c//dtd HTML 4.01 transitional//en\ ">");
Out.println ("<HTML>");
Out.println (" 

In actual development, these generated code and comments are generally not used by us, each time we have to manually delete these comments and code, it is cumbersome, so you can modify the servlet template code according to the development of the actual situation, change to meet the real development requirements of the template code. Here's an example of how to modify a servlet's template code with MyEclipse 10

The steps are as follows: Locate the \common\plugins folder under the MyEclipse installation directory, such as: D:\MyEclipse10\Common\plugins, and then find Com.genuitec.eclipse.wizards_ 9.0.0.me201108091322.jar This jar file, in order to easily find Com.genuitec.eclipse.wizards_9.0.0.me201108091322.jar this jar file, recommend the use of " searcheverything file Finder, as shown in the following illustration:
  
  
  
Open with the compression tool, note that the jar package is not unpacked, as shown in the following illustration:
   
   
Open com.genuitec.eclipse.wizards_9.0.0. Me201108091322.jar This jar file, you can see that there is a templates folder inside, enter the Templates folder, you can see that there is a Servlet.java file, as shown in the following figure:
    
To open the Servlet.java file, you can see the template code inside:
    

1 #---------------------------------------------# 2 # <aw:description>template for servlet</aw:description > 3 # <aw:version>1.1</aw:version> 4 # <aw:date>04/05/2003</aw:date> 5 # <aw:author&gt ; Ferret Renaud</aw:author> 6 #---------------------------------------------# 7 8 <aw:import>java.io.ioex Ception</aw:import> 9 <aw:import>java.io.PrintWriter</aw:import> <aw:import> Javax.servlet.servletexception</aw:import> <aw:import>javax.servlet.http.httpservlet</aw: Import> <aw:import>javax.servlet.http.HttpServletRequest</aw:import> <aw:import> Javax.servlet.http.httpservletresponse</aw:import> <aw:parentClass> Javax.servlet.http.httpservlet</aw:parentclass> <aw:constructor name= "C1" >/** * Con
 Structor of the object.
 * * Public <aw:className/> () {super (); 24 </aw:constructor> <aw:method name= "Doget" >/** * Doget method The servlet.
 <br> * This is called when a form has it tag value method equals to get. @param request the request send by the client to the server @param response the response Send by the "server to" client * @throws servletexception If an error occurred @throws IOException I         F An error occurred/doget public void (HttpServletRequest request, httpservletresponse response) 40
 Throws Servletexception, IOException {response.setcontenttype ("text/html");
 PrintWriter out = Response.getwriter (); Out.println (<!)
 DOCTYPE HTML public \-//w3c//dtd HTML 4.01 transitional//en\ ">");
 Out.println ("<HTML>"); Out.println (" 

Modify the template, according to your actual situation to modify, such as

Delete the code and method comments inside the doget and dopost, call Doget in the Dopost method, this is the template code that is modified according to the actual situation, after modification, save, restart MyEclipse, use MyEclipse to create the servlet, This is done with the template you just modified, and the generated code is as follows:
 

1 package gacl.servlet.study;
 2 
 3 import java.io.IOException;
 4 
 5 import javax.servlet.ServletException;
 6 Import Javax.servlet.http.HttpServlet;
 7 Import javax.servlet.http.HttpServletRequest;
 8 Import Javax.servlet.http.HttpServletResponse;
 9 Public 
class Servletnewtemplatecode extends HttpServlet {One
public     void Doget ( HttpServletRequest request, HttpServletResponse response)             throws Servletexception, IOException { 
the public     void DoPost (HttpServletRequest request, httpservletresponse response)             throws Servletexception, IOException {         doget (request, response); 
22}

In the way we develop, we can customize the servlet template according to our own development habits, and more or less improve on the efficiency of development, not every time the myeclipse generated a lot of code to delete.

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.