myEclips设置servlet模版教程

该文章参考了 https://www.cnblogs.com/xdp-gacl/p/3769058.html
当我们使用myEclips生成一个servlet时,生成的模版总会有一大堆东西,但我们可能只会用到其中几个方法,每次删除也会很麻烦,我们可以设置生成servlet模版,来解决这个问题!
我们来看具体的步骤:”

  1. 将myeclips关闭,因为不关闭 ,后面修改文件时会报出文件正在使用的提示,导致无法修改
  2. 找到myEclips的安装路径,例如我的myeclips就安装在D:\javaDev\myEclips,再找到安装目录下的 Common 文件夹下的plugins文件夹,然后 ctrl+F 搜索
    com.genuitec.eclipse.wizards_9.0.0 如下图 找到该文件,可能因为版本号等问题,该文件名后面一部分会略有不同
    这里写图片描述

然后右键该文件用压缩文件查看器打开,我这里用的好压
这里写图片描述
打开后 点击 templates 文件夹 可以看到 里面有一个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>
     *
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    }

</aw:method>

<aw:method name="doPost">
    /**
     * The doPost method of the servlet. <br>
     */
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            doGet(request,response);
    }

</aw:method>

<aw:method name="doPut">
    /**
     * The doPut method of the servlet. <br>
     *
     * This method is called when a HTTP put request is received.
     */
    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.
     */
    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>

然后保存,重开myEclips,创建一个servlet,模版已经生效,至此修改完成!

猜你喜欢

转载自blog.csdn.net/u013781343/article/details/80148797