myeclipse 2017 CI 中如何修改Servlet模板
myeclipse 2017 CI 中如何修改Servlet模板
在实际开发中,这些生成的代码和注释一般我们都用不到的,每次都要手工删除这些注释和代码,很麻烦,因此可以根据开发的实际情况修改Servlet的模板代码,改成符合实际开发需求的模板代码。
下面以MyEclipse 2017为例进行说明如何修改Servlet的模板代码,具体步骤如下:
找到 MyEclipse 2017 CI 安装目录下的 plugins 文件夹,比如我的:D:\learn\Java\MyEclipse\MyEclipse 2017 CI\plugins,然后找到 com.genuitec.eclipse.wizards_13.0.0.me201612231634.jar 这个jar文件,
打开 com.genuitec.eclipse.wizards_13.0.0.me201612231634.jar 这个jar文件后,可以看到里面有一个 templates 文件夹,进入 templates 文件夹,可以看到里面有一个 Servlet.java 文件。
修改里面的代码:删除 doGet 和 doPost 里面的代码和方法注释,在 doPost 方法里面调用 doGet ,这是根据实际情况修改成的模板代码,修改好之后,保存,重启 MyEclipse 2017 CI,使用MyEclipse创建Servlet,此时就是用刚才修改过的模板进行生成了。
(注意:在 MyEclipse 10 安装目录下的 \Common\plugins文件夹 ,注意文件夹的不同哦!)
<aw:import> 表示的是要导入的包,
<aw:parentClass> 表示该servlet继承的父类,
<aw:constructor 表示的是构造器,
<aw:method 表示的是方法的声明,
新的 Servlet.java 文件中的内容如下:
#---------------------------------------------# # <aw:description>Template for Servlet</aw:description> # <aw:version>1.1</aw:version> # <aw:date>04/05/2003</aw:date> # <aw:author>Ferret Renaud</aw:author> #---------------------------------------------# <aw:import>java.io.IOException</aw:import> <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"> public <aw:className/>() { super(); } </aw:constructor> <aw:method name="doGet"> public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } </aw:method> <aw:method name="doPost"> public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request,response); } </aw:method>
示例 XxxServlet.java 文件
1 package com.itheima.product.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 PayOnlineServlet extends HttpServlet { 11 12 @Override 13 public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 14 15 } 16 17 @Override 18 public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 19 doGet(request, response); 20 } 21 22 }
附上:旧的 Servlet.java 文件中的内容如下:
#---------------------------------------------# # <aw:description>Template for Servlet</aw:description> # <aw:version>1.1</aw:version> # <aw:date>04/05/2003</aw:date> # <aw:author>Ferret Renaud</aw:author> #---------------------------------------------# <aw:import>java.io.IOException</aw:import> <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"> /** * Constructor of the object. */ public <aw:className/>() { super(); } </aw:constructor> <aw:method name="doGet"> /** * The doGet method of the servlet. <br> * * This method is called when a form has its 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 the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) 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(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } </aw:method> <aw:method name="doPost"> /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) 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(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); } </aw:method> <aw:method name="doPut"> /** * The doPut method of the servlet. <br> * * This method is called when a HTTP put request is received. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Put your code here } </aw:method> <aw:method name="doDelete"> /** * The doDelete method of the servlet. <br> * * This method is called when a HTTP delete request is received. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Put your code here } </aw:method> <aw:method name="init"> /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } </aw:method> <aw:method name="destroy"> /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } </aw:method> <aw:method name="getServletInfo"> /** * Returns information about the servlet, such as * author, version, and copyright. * * @return String information about this servlet */ public String getServletInfo() { return "This is my default servlet created by Eclipse"; } </aw:method>
具体操作如下图所示:
我的博客园地址: http://www.cnblogs.com/chenmingjun
我的蚂蚁笔记博客地址: http://blog.leanote.com/chenmingjun
Copyright ©2018 黑泽明军
【转载文章务必保留出处和署名,谢谢!】

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
Java 学习(05)--数组
Java 学习(05)--数组 数组 1.数据类型:基本数据类型 引用数据类型(数组) 2.数组:存储同一种数据类型的多个元素的集合,也可看做是一个容器。 3.特点:1.每一个元素都有编号,从 0 开始,最大编号是长度 -1。 2.可以存放多个数据且数据类型相同 4.定义格式 A:数据类型 [] 数组名 ; B:数据类型 数组名 []; 推荐是用 A 方式, 数组的声明:数据类型[] 变量名 = new 数据类型[数组长度]; 5.数组的初始化 A:动态初始化时只指定数组长度,由系统为数组分配初始值,如果数组中没有指定初始值, java 虚拟机会给它分配一个默认的初始值 举例: int[] arr = new int[3]; byte short int 0 long 0L float,double 0.0 char '\u0000' boolean false 引用类型 null 数据使用完毕后,在垃圾回收器空闲的时候回收。 B:静态初始化 给出值,系统决定长度 举例: int[] arr = new int[]{1,2,3}; 简化版: int[] arr = {1,2...
- 下一篇
Python3 基础语法
编码 默认情况下,Python 3 源码文件以UTF-8编码,所有字符串都是 unicode 字符串。 当然你也可以为源码文件指定不同的编码: # -*- coding: cp-1252 -*- 上述定义允许在源文件中使用 Windows-1252 字符集中的字符编码,对应适合语言为保加利亚语、白罗斯语、马其顿语、俄语、塞尔维亚语。 标识符 第一个字符必须是字母表中字母或下划线_。 标识符的其他的部分由字母、数字和下划线组成。 标识符对大小写敏感。 在 Python 3 中,非 ASCII 标识符也是允许的了。 python保留字 保留字即关键字,我们不能把它们用作任何标识符名称。Python 的标准库提供了一个 keyword 模块,可以输出当前版本的所有关键字: >>> import keyword >>> keyword.kwlist ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- CentOS7设置SWAP分区,小内存服务器的救世主
- Mario游戏-低调大师作品
- Docker使用Oracle官方镜像安装(12C,18C,19C)
- 2048小游戏-低调大师作品
- Jdk安装(Linux,MacOS,Windows),包含三大操作系统的最全安装
- MySQL8.0.19开启GTID主从同步CentOS8
- CentOS8安装Docker,最新的服务器搭配容器使用
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- CentOS7编译安装Cmake3.16.3,解决mysql等软件编译问题