1. 程式人生 > >修改MyEclipse 10的Servlet、JSP模版程式碼

修改MyEclipse 10的Servlet、JSP模版程式碼

我們在建立Servlet、Jsp、Html時使用MyEclipse 10會自動生成一些程式碼和註釋,但很多時候我們不需要這些程式碼的,這時就需要手動刪除,這樣會比較費時間,此時我們可以修改MyEclipse的模板程式碼,生成Servlet、Jsp時就沒有多餘的程式碼了。

以MyEclipse 10為例

首先找到MyEclipse 10的安裝目錄


找到“com.genuitec.eclipse.wizards_9.0.0.me201108091322.jar”包,這個包就是存放模板程式碼的,只要修改這個包,我們生成的程式碼就會改變。每個版本的MyEclipse修改方法可能不一樣。

通過解壓工具開啟就可以看到“templates”目錄,這裡就存放著Servlet、Jsp、Html等的嚮導模板


不用解壓,直接雙擊“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>


修改後的程式碼

#---------------------------------------------#
# <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">

	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>

<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>

直接儲存到jar包上,再重新開啟MyEclipse生成Servlet

這時使用導向生成的Servlet就簡潔多了


package com.dmt.session;

import java.io.IOException;

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

public class Session2 extends HttpServlet {

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

	}

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

		doGet(request, response);
	}

}

這樣生成的Servlet程式碼就沒有多餘的了。

Jsp模板程式碼的修改也是類似的


只要修改《Jsp.vtl》檔案就行了,還有html也一樣。這裡就不多介紹了。

相關推薦

修改MyEclipse 10的ServletJSP模版程式碼

我們在建立Servlet、Jsp、Html時使用MyEclipse 10會自動生成一些程式碼和註釋,但很多時候我們不需要這些程式碼的,這時就需要手動刪除,這樣會比較費時間,此時我們可以修改MyEclipse的模板程式碼,生成Servlet、Jsp時就沒有多餘的程式碼了。 以

HIVE的安裝配置mysql的安裝hive建立表建立分割槽修改表等內容hive beeline使用HIVE的四種資料匯入方式使用Java程式碼執行hive的sql命令

1.上傳tar包 這裡我上傳的是apache-hive-1.2.1-bin.tar.gz 2.解壓 mkdir -p /home/tuzq/software/hive/ tar -zxvf apache-hive-1.2.1-bin.tar.gz  -C /home/

程式設計師的小技能,1行程式碼修改開機密碼1張圖片讓你電腦宕機

程式設計師很忙,忙著敲程式碼debug,程式設計師有時候也很閒,閒下來的就是就開始自黑,自黑的段子越來越多還被編出了一首詩:“格子襯衫雙肩包、錢多話少死得早,晚睡晚起加班多,沒事就和產品吵”。這屬於藝術,來源於生活,也高於生活,有了誇張的成分。 程式設計師作為一個門檻較高的職業,從業人員的

jsp頁面中的java程式碼(jsp表示式jsp小指令碼jsp宣告)

jsp頁面中的java程式碼,有三種:jsp表示式、jsp小指令碼、jsp宣告。 編寫位置:頁面的任意位置。 作用:控制頁面中可變內容的產生。 1.jsp表示式 語法規則:<%= ... %> 轉譯成 Servlet 時的規則:在 service()方法中用 o

1如何修改MyEclipse 或 Eclipse 中.properties 的Unicode編碼

每當我開啟Eclipse 或者是MyEclipse的**.properties中後。或是自己新建的一個*.properties。然後再進行寫入中文後,你就會發現你所輸入的中文都變成了Unicode碼。如下: 那麼我們需要把Unicode轉換成UTF-8的格

SQLServer觸發器建立刪除修改檢視示例程式碼

一: 觸發器是一種特殊的儲存過程﹐它不能被顯式地呼叫﹐而是在往表中插入記錄﹑更新記錄或者刪除記錄時被自動地啟用。所以觸發器可以用來實現對錶實施複雜的完整性約束。 二: SQL Server為每個觸發器都建立了兩個專用表:Inserted表和Deleted表。這兩個表。一:

STM32系列修改外部晶振以及程式碼修改(f103f105為例)

剛剛接觸STM32的時候,用的都是8M晶振。比如你想更換到為外部晶振為12M,但是主頻仍想用72M的。該如何設定?或者想倍頻到更高的主頻該怎麼修改? 例子就直接直接拿<正點原子>的例子吧! 屬性 原來 現在 外部晶

讀取URL中的引數修改URL引數動態修改URL replaceState js程式碼

都是抄來的知識彙總 1、讀取URL中的引數值 /* *獲取URL引數 */ function GetQueryString(name) {     var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$

如何修改myeclipse 新建JSP檔案時的預設模板

第一種方法: MyEclipse 6.0\myeclipse\eclipse\plugins\com.genuitec.eclipse.wizards_6.0.1.zmyeclipse601200710\templates\jsp  修改Jsp.vtl這個檔案就可以了

intellij idea開發環境下使用jetty跑專案修改jsjsp檔案提示Cannot Save Files 問題

問題描述如題,試了好久終於找到解決辦法,記錄下來與大家分享:1、首先進入你的maven倉庫找到jetty的位置,我的位置在:C:\Users\ccpit\.m2\repository\org\mortbay(供大家參考)2、進入jetty目錄,找到你的jetty引用jar包,

Myeclipse檢視修改設定快捷鍵

       MyEclipse,是一個十分優秀的用於開發Java, J2EE的Eclipse外掛集合,MyEclipse的功能非常強大,支援也十分廣泛,尤其是對各種開源產品的支援十分不錯,在使用My

Excel--使用VBA Code 動態建立修改和刪除自定義窗體程式碼摘抄

Sub CreateUserform()'PURPOSE: Create & Modify a Userform with VBA Code'AUTHOR: John Walkenbach (www.SpreadsheetPage.com)'SOURCE: www.

c語言要修改或者讀取更改txt的話,真的需要好好看下程式碼

在C語言中寫檔案 //獲取檔案指標 FILE *pFile = fopen("1.txt", "w"); fwrite ("hello",1,strlog("hello"), pFile); fflush(pFile); 在C語言中讀檔案 FILE *pFile=fo

struts2jsp分頁程式碼

分頁樣式 一上傳這圖片就被打上了水印,暈。 <%@ page language="java" pageEncoding="UTF-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <s:if t

純css修改單選復選按鈕樣式

class radi html inpu con cnblogs margin clas 單選 只支持IE9及以上 html <label><input class="radio" type="radio" name="radio1"/><s

[linux][mysql] 命令更改表結構:添加刪除修改字段調整字段順序

.com col inf size type unsigned rim alter name 原文出處:http://www.phpernote.com/MySQL/1120.html 1 常用的通過mysql命令來更改表結構的一些sql語句,包括添加、刪除、修改字

Linux下查看/修改系統時區時間

英國倫敦 sha 硬件時間 創建 com rec shanghai asi deb 一、查看和修改Linux的時區 1. 查看當前時區 命令 : "date -R" 2. 修改設置Linux服務器時區 方法 A 命令 : "tzselect" 方法 B 僅限於RedHat

修改MyEclipse工作空間

clip aec for 我們 index baidu step ash 項目內容 MyEclipse如何更改工作空間,MyEclipse是java開發常用工具,在開發的過程中我們會經常切換工作空間來切換項目內容,初學者來說有必要講一下如何切換工作空間

修改myeclipse字體與操作系統的字體一致

系統 找到 uri win myeclipse 選擇 -- edi appear 如果你是win7系統,想要修改Myeclipse字體,步驟如下:第一步:C:\Windows\Fonts,找到Courier New,鼠標右鍵-->顯示第二步:Ceneral -->

提交form表單---修改密碼 ajaxjQuery

改密 func 表單 eset password servlet 驗證 確認密碼 密碼 <form id ="password" method="post">   <table > <tr>   <td>原密碼:<