MyEclipse自定义servlet模板
Posted 代码小杨
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MyEclipse自定义servlet模板相关的知识,希望对你有一定的参考价值。
- 每次用MyEclipse默认的servlet的模板创建servlet的时候,里面会生成好多没有用的代码。因此,我们可以自定义servlet模板。步骤如下:
- 找到com.genuitec.eclipse.wizards_11.5.0.me201310291746.jar 文件,该文件在MyEclipse(本人安装的是MyEclipse Professional 2014)安装目录下的/plugins下
- 打开com.genuitec.eclipse.wizards_11.5.0.me201310291746.jar,找到templates
- 进入templates里面有Servlet.java文件,打开,修改里面的代码,就可以自己定义自己想要的servlet模板。
- 打开Servlet.java文件,修改里面的代码为:
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> 10 11 <aw:method name="doGet"> 12 public void doGet(HttpServletRequest request, HttpServletResponse response) 13 throws ServletException, IOException { 14 15 } 16 17 </aw:method> 18 19 <aw:method name="doPost"> 20 21 public void doPost(HttpServletRequest request, HttpServletResponse response) 22 throws ServletException, IOException { 23 doGet(request,response); 24 25 } 26 27 </aw:method>
- 然后创建出来的servlet为如下样式:
1 package com.bookStore.web.servlet; 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 10 public class LoginServlet extends HttpServlet { 11 12 public void doGet(HttpServletRequest request, HttpServletResponse response) 13 throws ServletException, IOException { 14 15 } 16 17 public void doPost(HttpServletRequest request, HttpServletResponse response) 18 throws ServletException, IOException { 19 doGet(request, response); 20 21 } 22 23 }
以上是关于MyEclipse自定义servlet模板的主要内容,如果未能解决你的问题,请参考以下文章