现在的位置: 首页 > 综合 > 正文

修改 myeclipse8.5 jsp 模板

2013年08月31日 ⁄ 综合 ⁄ 共 9463字 ⁄ 字号 评论关闭

在MyEclipse中新建一个JSP页面后,为了让页面显示中文,我们总要做将page指令中的pageEncoding="UTF-8"或 pageEncoding="GBK"之类的动作,每新建一个页面就要更改一次,很麻烦吧,现在告诉大家一个方法,可以再也不用做这无聊而又麻烦的动作了。

 还有 meta 标签,也可以去掉

 修改 DOCTYPE  标签

关键字: jsp模板 在  D:\Program Files\Genuitec\Common\plugins

 

修改过程中,建议关掉MyEclipse

 

1.找到Genuitec\Common\plugins下的com.genuitec.eclipse.wizards_8.5.0.zmyeclipse75020090612.jar

(

  • "Common"和"MyEclipse 8.5"同在"Genuitec"文件夹下
  • 搜索:com.genuitec.eclipse.wizards,迅速定位到com.genuitec.eclipse.wizards_8.5.0.zmyeclipse75020090612.jar
  • 以防万一,建议先备份那个.jar包

)

2.选择使用WinRAR打开

3.在WinRAR里,依次进入: templates --->jsp

4.最后打开Jsp-html.vtl 和 Jsp.vtl (主要)

5.按照自己喜欢的风格,对其进行修改

 

我将其修改如下:

Java代码
复制代码
 收藏代码
  1. #*---------------------------------------------#   
  2. # Template for a JSP as HTML   
  3. @version1.2  
  4. @author: Ferret Renaud   
  5. @author: Jed Anderson   
  6. #---------------------------------------------#   
  7. *#<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.*" session="true"%>
      
  8. <%@ page import="java.text.*" %>   
  9. <%--   
  10. <%@ taglib uri="/struts-tags" prefix="s"%>   
  11. --%>    
  12. <%   
  13. String path = request.getContextPath();   
  14. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
  15. %>   
  16. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  17. <html xmlns="http://www.w3.org/1999/xhtml">   
  18. <head>   
  19.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
  20.     <title>set your title</title>   
  21.     <!--   
  22.     <link rel="stylesheet" type="text/css" href="CSS.css" />   
  23.     <script language="JavaScript" type="text/javascript" src="jquery.js"></script>   
  24.     -->     
  25.     <script language="JavaScript" type="text/javascript" src="Macrotea-CommonHelper.js"></script>   
  26.     <style type="text/css">   
  27.        
  28.     </style>   
  29.        
  30.     <script type="text/javascript">   
  31.        
  32.     </script>   
  33. </head>   
  34.   
  35. <body>   
  36.   
  37.   
  38. </body>   
  39.   
  40. </html>  

 

  

7.如果你喜欢,也可以对html进行修改,使其方便自己。

 

Java代码
复制代码
 收藏代码
  1. #*---------------------------------------------#   
  2. # Template for an HTML file   
  3. @version1.3  
  4. @author Ferret Renaud   
  5. @author Jed Anderson   
  6. #----------------------------------------------#   
  7. *#<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">    
  8. <html xmlns="http://www.w3.org/1999/xhtml">   
  9. <head>   
  10. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  11. <title>set your title</title>   
  12. <!--   
  13.     <link rel="stylesheet" type="text/css" href="CSS.css" />   
  14.     <script language="JavaScript" type="text/javascript" src="jquery.js"></script>   
  15. -->     
  16.     <script language="JavaScript" type="text/javascript" src="Macrotea-CommonHelper.js"></script>   
  17.     <style type="text/css">   
  18.        
  19.     </style>   
  20.        
  21.     <script type="text/javascript">   
  22.        
  23.     </script>   
  24. </head>   
  25.   
  26. <body>   
  27.   
  28.   
  29.   
  30.   
  31.   
  32.   
  33. </body>   
  34.   
  35. </html>  

  

Servlet模板:

 

Java代码
复制代码
 收藏代码
  1. #---------------------------------------------#   
  2. # <aw:description>Template for Servlet</aw:description>   
  3. # <aw:version>1.1</aw:version>   
  4. # <aw:date>04/05/2003</aw:date>
      
  5. # <aw:author>Ferret Renaud</aw:author>   
  6. #---------------------------------------------#   
  7.   
  8. <aw:import>java.io.IOException</aw:import>   
  9. <aw:import>java.io.PrintWriter</aw:import>   
  10.   
  11. <aw:import>javax.servlet.ServletException</aw:import>   
  12. <aw:import>javax.servlet.http.HttpServlet</aw:import>   
  13. <aw:import>javax.servlet.http.HttpServletRequest</aw:import>   
  14. <aw:import>javax.servlet.http.HttpServletResponse</aw:import>   
  15.   
  16. <aw:parentClass>javax.servlet.http.HttpServlet</aw:parentClass>   
  17.   
  18.     private HttpSession session;   
  19.     private RequestDispatcher dispatcher;   
  20.        
  21. <aw:constructor name="c1">   
  22.   
  23.     public <aw:className/>() {   
  24.         super();   
  25.     }   
  26.   
  27. </aw:constructor>    
  28.     
  29. <aw:method name="doGet">   
  30.   
  31.     public void doGet(HttpServletRequest request, HttpServletResponse response)   
  32.         throws ServletException, IOException {   
  33.         /*Prepare*/  
  34.         response.setContentType("text/html");   
  35.         response.setCharacterEncoding("UTF-8");   
  36.         session = request.getSession();   
  37.         dispatcher=request.getRequestDispatcher("/servlet/login.do");   
  38.   
  39.   
  40.     }   
  41.   
  42. </aw:method>   
  43.   
  44. <aw:method name="doPost">   
  45.   
  46.     public void doPost(HttpServletRequest request, HttpServletResponse response)   
  47.         throws ServletException, IOException {   
  48.         doGet(request, response);   
  49.     }   
  50.   
  51. </aw:method>   
  52.   
  53. <aw:method name="doPut">   
  54.   
  55.     public void doPut(HttpServletRequest request, HttpServletResponse response)   
  56.         throws ServletException, IOException {   
  57.   
  58.            
  59.     }   
  60.   
  61. </aw:method>   
  62.   
  63. <aw:method name="doDelete">   
  64.   
  65.     public void doDelete(HttpServletRequest request, HttpServletResponse response)   
  66.         throws ServletException, IOException {   
  67.   
  68.            
  69.     }   
  70.   
  71. </aw:method>   
  72.   
  73. <aw:method name="init">   
  74.   
  75.     public void init() throws ServletException {   
  76.         super.init();   
  77.     }   
  78.   
  79. </aw:method>   
  80.   
  81. <aw:method name="destroy">   
  82.   
  83.     public void destroy() {   
  84.         super.destroy();   
  85.         session=null;    
  86.         dispatcher=null;   
  87.     }   
  88.   
  89. </aw:method>   
  90.   
  91. <aw:method name="getServletInfo">   
  92.   
  93.     public String getServletInfo() {   
  94.         return "This is my default servlet created by Eclipse";   
  95.     }   
  96.   
  97. </aw:method>  

 

 

 

8.最后WinRAR提示是否保存对jar包的修改,“是”就行了。

 

MyEclipse中默认的文档开头是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

其对CSS的支持不太好,因此还是改成兼容性好点的,建议从DW中复制过来。

 

10.这下爽了。方便很多了。

 

**我自己的最小效果

#*---------------------------------------------#
# Template for a JSP
# @version: 1.2
# @author: Ferret Renaud
# @author: Jed Anderson
#---------------------------------------------#
*#<%@ page language="java" import="java.util.*" pageEncoding="$encoding"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP '$title' starting page</title>

  </head>
  
  <body>
    This is my JSP page. <br>
  </body>
</html>

 

抱歉!评论已关闭.