修改Servlet模板中的doPost(),doGet()方法

原Servlet模板

#---------------------------------------------#
# Template for Servlet
# 1.1
# 04/05/2003
# Ferret Renaud
#---------------------------------------------#

java.io.IOException
java.io.PrintWriter

javax.servlet.ServletException
javax.servlet.http.HttpServlet
javax.servlet.http.HttpServletRequest
javax.servlet.http.HttpServletResponse

javax.servlet.http.HttpServlet


    /**
     * Constructor of the object.
     */
    public () {
        super();
    }

 
 

    /**
     * The doGet method of the servlet. 
* * 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( ""); out.println(""); out.println(" A Servlet"); out.println(" "); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" "); out.println(""); out.flush(); out.close(); }
/** * The doPost method of the servlet.
* * 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( ""); out.println(""); out.println(" A Servlet"); out.println(" "); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" "); out.println(""); out.flush(); out.close(); }
/** * The doPut method of the servlet.
* * 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 }
/** * The doDelete method of the servlet.
* * 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 }
/** * Initialization of the servlet.
* * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here }
/** * Destruction of the servlet.
*/ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here }
/** * 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"; }

修改方法

  • 找到MyEclipse2014(其他版本也差不多)的安装目录下的plugins文件,并打开
  • 在搜索框里查找这个文件(如图)
修改Servlet模板中的doPost(),doGet()方法_第1张图片
查找此jar文件
  • 打开此压缩文件(注意不要解压,直接打开就好),打开文件找模版templates,在template下再找servlet.java
  • 修改servlet.java就行。不过修改之前请记得备份哦,这个你懂。。。

为了开发的便捷,我修改了Servlet模板中的doPost(),doGet()方法

如下是我修改的模板


    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        
    }




    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

        doGet(request,response);
    }


你可能感兴趣的:(修改Servlet模板中的doPost(),doGet()方法)