MyEclipse 9.0 自定义创建JSP模板的方法
在MyEclipse中新建一个JSP页面后,为了让页面显示中文,我们总要做将page指令中的pageEncoding="UTF-8"或 pageEncoding="GBK"之类的动作,每新建一个页面就要更改一次,相当的麻烦,特此到网上查找了解决方法,通过新建自己的JSP模版来解决这种烦恼,特此归结下方法的步骤:
一、首先要关掉myeclipse9,如果不关掉myeclipse9,则无法修改myeclipse9安装目录里的所有内容,下面的操作将无法进行;
二、在myeclipse9的安装目录下面找到
D:\Program Files\MyEclipse 9.0\Common\plugins\com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar
其中:9.0.0是版本号, 201103012021可能是编译时间或者打包时间 你的这两个值可能不一样 但是其他都会一样。
三、然后用rar或者解压缩软件打开,进入templates\jsp文件夹,看到很多模板。
D:\Program Files\MyEclipse 9.0\Common\plugins\com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar
其中:9.0.0是版本号, 201103012021可能是编译时间或者打包时间 你的这两个值可能不一样 但是其他都会一样。
三、然后用rar或者解压缩软件打开,进入templates\jsp文件夹,看到很多模板。
四、随便复制一个模板出来(如:Jsp.vtl)。
五、修改你复制出来的模板(使用笔记本或者editplus打开进行修改)。比如我首先把文件名修改成JspOfSerein.vtl ,接着打开将模版的代码修改如下:
#*---------------------------------------------# # Template for a JSP <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType=" text/html; charset=UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Serein's JSP '$title' Page</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="description" content="This is Serein's page"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> This is Serein's JSP page. <br> </body> </html>
六、修改完成后,然后保存,并将其添加到com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar包里面去(直接拉进刚才用压缩包打开的templates\jsp文件夹里)。
七、从查看解压文件的界面中,返回到根目录(即com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar目录),找到模版配置文件templates.xml ,同笔记本或者editplus打开进行修改。修改如下:在<templateLibrary>里添加如下元素;
#*---------------------------------------------# # Template for a JSP <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page contentType=" text/html; charset=UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Serein's JSP '$title' Page</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="description" content="This is Serein's page"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> This is Serein's JSP page. <br> </body> </html>
六、修改完成后,然后保存,并将其添加到com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar包里面去(直接拉进刚才用压缩包打开的templates\jsp文件夹里)。
七、从查看解压文件的界面中,返回到根目录(即com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar目录),找到模版配置文件templates.xml ,同笔记本或者editplus打开进行修改。修改如下:在<templateLibrary>里添加如下元素;
<template
context="com.genuitec.eclipse.wizards.jsp"
script="templates/jsp/JspOfSerein.vtl"
name="Serein-JSP template"/>
其中:
1、templates/jsp/JspOfSerein.vtl:为第五步时所修改并添加的模板和相对路径。
2、Serein-JSP template:为MyEclipse中所要标识的模版名称,MyEclipse新建JSP文件时通过这个名字来选择对应的模版。
3、context="com.genuitec.eclipse.wizards.jsp" 这个一定要存在,并且跟其他jsp模板的设置一样,复制就可以。
1、templates/jsp/JspOfSerein.vtl:为第五步时所修改并添加的模板和相对路径。
2、Serein-JSP template:为MyEclipse中所要标识的模版名称,MyEclipse新建JSP文件时通过这个名字来选择对应的模版。
3、context="com.genuitec.eclipse.wizards.jsp" 这个一定要存在,并且跟其他jsp模板的设置一样,复制就可以。
八、修改完成后,将templates.xml另外保存出来(保存到桌面)待用,然后将com.genuitec.eclipse.wizards_9.0.0.me201103012021.jar包中的templates.xml删除,最后将我们修改的templates.xml添加进去完成替换修改工作。
九、重新打开myeclipse9,点new/jsp,在JSP新建向导的"template to use"的下拉框里,将多出了我们所新建的模板——Serein-Jsp template,见图:
点击“finish”完成JSP的新建,得到的JSP页面模版代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'TEST.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
</body>
</html>
这种方法应该可以适用于创建添加其它的模版!
这种方法应该可以适用于创建添加其它的模版!
参考来源:http://panyongzheng.iteye.com/blog/1102081
http://iscode.iteye.com/blog/628548