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 }
XxxServlet.java
附上:旧的 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>
具体操作如下图所示:
我的GitHub地址:https://github.com/heizemingjun
我的博客园地址:http://www.cnblogs.com/chenmingjun
我的蚂蚁笔记博客地址:http://blog.leanote.com/chenmingjun
Copyright ©2018 黑泽明军
【转载文章务必保留出处和署名,谢谢!】
myeclipse 2017 CI 中如何修改Servlet模板相关推荐
- myeclipse中如何修改Servlet模板
在实际开发中,这些生成的代码和注释一般我们都用不到的,每次都要手工删除这些注释和代码,很麻烦,因此可以根据开发的实际情况修改Servlet的模板代码,改成符合实际开发需求的模板代码.下面以MyEcli ...
- MyEclipse 2017 CI 9 发布(附下载)
2019独角兽企业重金招聘Python工程师标准>>> 挑战全年最低价!MyEclipse线上狂欢继续!火热开启中>> 在进入年底之时,2017 CI 9是我们最大的版本 ...
- myeclipse 2017 ci 10 破解包+教程(亲测已成功)
准备工作: 下载破解包: myeclipse 2017 ci 10 破解包:链接:https://pan.baidu.com/s/16xZ3kiaOGYCybOebWpdqUg 密码:eq1d 下载M ...
- MyEclipse 2017 CI 10 发布(附下载)
挑战全年最低价!MyEclipse线上狂欢仅剩最后3天!立即抢购>> 2017 CI 10主要是一个错误修复版本,这个版本为Angular和TypeScript工具提供了重要的修复,并为I ...
- MyEclipse修改Servlet模板
进入myeclipse的安装路径 然后进入plugins文件夹 打开搜索框,输入 *wizard* 找到名字是 com.genuitec.eclipse.wizards_11.5.0.me201310 ...
- Idea中修改servlet模板
1.点击左上角的File: Setting --> Editor --> File and Code Templates --> Other --> web -->Ser ...
- MyEclipse自动生成注释,修改注释模板
以下学习过程中的笔记,部分内容来自网络和书籍.一方便以后查阅,二希望能帮助到别人,三希望高手指点. 用Myeclipse开发项目是,自动生成注释十分方便快捷,但我们希望自动生成自己的名字和一些内容,同 ...
- IDEA中修改自动生成的Servlet模板,提高编码效率
IDEA中修改自动生成的Servlet模板,提高编码效率 一.修改idea中生成的servlet模板原因 自动生成的servlet模块代码,不够智能,还需要手动进行修改 二.修改Servlet模板 三 ...
- jsp之servlet模板问题
如果你在web项目下创建一个Servlet类,那么它会自带很多东西,比如有很多的注释,还有很多out.println()语句等.可能这些东西都不是你需要,这样看起来就会比较的令人不爽.下面的话就教大家 ...
最新文章
- usaco Superprime Rib
- NYOJ 士兵杀敌(二) 树状数组
- mysql 的独占锁和排它锁_MySQL的排它锁与共享锁
- python中range 函数_Python中的range函数
- IBatisNet + Castle 开发相关文章
- 微软账号被暂时停用咋办_游戏账号交易要注意什么?买游戏账号有哪些可能会被找回去...
- HTML:HTML界面实现HTML代码编译运行界面
- 全球五十家知名传感器制造商分布盘点、特点分析
- 小米开源便签Notes-源码研究(0)-整体功能介绍(图文并茂)
- AcWing1402. 星空之夜
- uniapp H5公众号errMsg: “onMenuShareAppMessage:fail, the permission value is offline verifying“
- Qt开发,应用程序错误,应用程序无法正常启动0xc000007b
- centos 文件分割
- 《区块链助力粤港澳大湾区一体化发展报告(2022)》发布
- js 将一大段时间均分为很多个小时间段
- jdk api 1.8 -中文版
- 前端常用的文档及组件库
- 走向架构师必备的技能
- 教你无脑式安装Xshell、Xftp,快速远程连接使用Linux服务器并且高效传输文件(保姆级教程)
- 全国计算机等级考试过关条件,谈全国计算机等级考试二级过关心得经验(1)...
热门文章
- 模型集成01-Bagging/Boosting/Stacking
- 数据挖掘十大经典算法(9) 朴素贝叶斯分类器 Naive Bayes
- sql server 2005 修改动态端口,连接字符串为:需要改成:IP地址+逗号+端口号才行...
- 【P000-008】交易费计算系统,1.1版
- [转载]url带中文参数显示乱码的问题
- c++ primer 函数传值1
- 简单句(Simple sentences)-one
- 3516a 自带的ive 算子的运行情况分析
- Alt+/ 快速提示快捷键修复及ecplise心得
- Symbol'' has different size in shared object,consider re-linking