- Every time you create a servlet with a template that myeclipse the default servlet, it generates a lot of unused code. Therefore, we can customize the servlet template. The steps are as follows:
- Locate the com.genuitec.eclipse.wizards_11.5.0.me201310291746.jar file in MyEclipse (i installed the MyEclipse Professional 2014) Under the installation directory under /plugins
- Open Com.genuitec.eclipse.wizards_11.5.0.me201310291746.jar and find templates .
- Into the templates inside there are servlet.java files, open, modify the code inside, you can define your own desired servlet template.
- Open the Servlet.java file and modify the code inside to:
1 <Aw:import>Java.io.IOException</Aw:import>2 <Aw:import>Java.io.PrintWriter</Aw:import>3 4 <Aw:import>Javax.servlet.ServletException</Aw:import>5 <Aw:import>Javax.servlet.http.HttpServlet</Aw:import>6 <Aw:import>Javax.servlet.http.HttpServletRequest</Aw:import>7 <Aw:import>Javax.servlet.http.HttpServletResponse</Aw:import>8 9 <Aw:parentclass>Javax.servlet.http.HttpServlet</Aw:parentclass>Ten One <Aw:methodname= "Doget"> A Public void Doget (HttpServletRequest request, httpservletresponse response) - throws Servletexception, IOException { - the } - - </Aw:method> - + <Aw:methodname= "DoPost"> - + Public void DoPost (HttpServletRequest request, httpservletresponse response) A throws Servletexception, IOException { at doget (request,response); - - } - - </Aw:method>
View Code
- The servlet is then created with the following style:
1 PackageCom.bookStore.web.servlet;2 3 Importjava.io.IOException;4 5 Importjavax.servlet.ServletException;6 ImportJavax.servlet.http.HttpServlet;7 Importjavax.servlet.http.HttpServletRequest;8 ImportJavax.servlet.http.HttpServletResponse;9 Ten Public classLoginservletextendsHttpServlet { One A Public voiddoget (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { - the } - - Public voidDoPost (httpservletrequest request, httpservletresponse response) - throwsservletexception, IOException { + doget (request, response); - + } A at}
View Code
MyEclipse Custom servlet templates