柚子快報(bào)激活碼778899分享:
柚子快報(bào)激活碼778899分享:
35 * @param response the response send by the server to the client 36 * @throws ServletException if an error occurred 37 * @throws IOException if an error occurred 38 */ 39 public void doGet(HttpServletRequest request, HttpServletResponse response) 40 throws ServletException, IOException { 41 42 response.setContentType(“text/html”); 43 PrintWriter out = response.getWriter(); 44 out.println( 45 “”); 46 out.println(“”); 47 out.println(" A Servlet“); 48 out.println(” “); 49 out.print(” This is “); 50 out.print(this.getClass()); 51 out.println(”, using the GET method"); 52 out.println(" “); 53 out.println(”“); 54 out.flush(); 55 out.close(); 56 } 57 58 59 60

?修改該模板,根據(jù)自己的實(shí)際情況進(jìn)行修改,比如
![]()
刪除doGet和doPost里面的代碼和方法注釋,在doPost方法里面調(diào)用doGet,這是根據(jù)實(shí)際情況修改成的模板代碼,修改好之后,保存,重啟MyEclipse,使用MyEclipse創(chuàng)建Servlet,此時(shí)就是用剛才修改過的模板進(jìn)行生成了,生成的代碼如下:

1 package gacl.servlet.study; 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 ServletNewTemplateCode extends HttpServlet { 11 12 public void doGet(HttpServletRequest request, HttpServletResponse response) 13 throws ServletException, IOException { 14 15 } 16 17 public void doPost(HttpServletRequest request, HttpServletResponse response) 18 throws ServletException, IOException { 19 doGet(request, response); 20 } 21 22 }

### 二、修改jsp的默認(rèn)模板
同樣也是找到**com.genuitec.eclipse.wizards\_9.0.0.me201108091322.jar**這個(gè)jar文件,用壓縮工具打開,進(jìn)入templates\jsp文件夾,可以看到MyEclipse自帶的那些jsp模板,如下圖所示:
![]()
這些jsp模板是MyEclipse自帶的,我們也可以依樣畫葫蘆,根據(jù)平時(shí)項(xiàng)目開發(fā)中的實(shí)際情況,創(chuàng)建一個(gè)jsp模板,然后添加到j(luò)sp目錄中,操作步驟如下:
**1、隨便復(fù)制一個(gè)jsp模板出來(如:Jsp.vtl),復(fù)制到系統(tǒng)的桌面或者系統(tǒng)的其他盤進(jìn)行存儲(chǔ)**
![]()
**2、修改復(fù)制出來的模板,使用記事本或者editplus打開Jsp.vtl,可以看到Jsp.vtl的模板代碼,如下所示:**

1 #*---------------------------------------------# 2 # Template for a JSP 3 # @version: 1.2 4 # @author: Ferret Renaud 5 # @author: Jed Anderson 6 #---------------------------------------------# 7 *#<%@ page language=“java” import=“java.util.*” pageEncoding="
e
n
c
o
d
i
n
g
"
8
<
9
S
t
r
i
n
g
p
a
t
h
=
r
e
q
u
e
s
t
.
g
e
t
C
o
n
t
e
x
t
P
a
t
h
(
)
;
10
S
t
r
i
n
g
b
a
s
e
P
a
t
h
=
r
e
q
u
e
s
t
.
g
e
t
S
c
h
e
m
e
(
)
+
"
:
/
/
"
+
r
e
q
u
e
s
t
.
g
e
t
S
e
r
v
e
r
N
a
m
e
(
)
+
"
:
"
+
r
e
q
u
e
s
t
.
g
e
t
S
e
r
v
e
r
P
o
r
t
(
)
+
p
a
t
h
+
"
/
"
;
111213
<
!
D
O
C
T
Y
P
E
H
T
M
L
P
U
B
L
I
C
"
?
/
/
W
3
C
/
/
D
T
D
H
T
M
L
4.01
T
r
a
n
s
i
t
i
o
n
a
l
/
/
E
N
"
>
14
<
h
t
m
l
>
15
<
h
e
a
d
>
16
<
b
a
s
e
h
r
e
f
=
"
<
1718
<
t
i
t
l
e
>
M
y
J
S
P
′
encoding"%> 8 <% 9 String path = request.getContextPath(); 10 String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 11 %> 12 13 14 15
16encoding"8<9Stringpath=request.getContextPath();10StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";1112131415
16
這是Jsp.vtl的模板原始代碼,這個(gè)模板的代碼對(duì)于我來說不太符合項(xiàng)目開發(fā)中的實(shí)際情況,需要修改,修改后的模板如下:

1 #*---------------------------------------------# 2 # Template for a JSP 3 # @version: 1.2 4 # @author: 孤傲蒼狼 5 #---------------------------------------------# 6 *#<%@ page language=“java” pageEncoding=“UTF-8”%> 7 8 9 10 11 12 13 14 15 16

為了避免覆蓋原來的Jsp.vtl模板,將修改后的Jsp.vtl模板重命名,例如重命名成gacl.vtl。
**3.將gacl.vtl模板復(fù)制,然后粘貼到com.genuitec.eclipse.wizards\_9.0.0.me201108091322.jar包里面的templates\jsp文件夾里。**

4、從查看解壓文件的界面中,返回到根目錄(即**com.genuitec.eclipse.wizards\_9.0.0.me201108091322.jar**目錄),找到模版配置文件templates.xml,如下圖所示:
![]()
同樣,將templates.xml文件復(fù)制到桌面,使用記事本或者editplus打開進(jìn)行修改。
修改如下:在
1
### 分享
**[開源分享:【大廠前端面試題解析+核心總結(jié)學(xué)習(xí)筆記+真實(shí)項(xiàng)目實(shí)戰(zhàn)+最新講解視頻】](https://bbs.csdn.net/topics/618166371)**


柚子快報(bào)激活碼778899分享:
好文鏈接
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。