您的位置:首页 > 编程语言 > Java开发

MyEclipse 中修改和增加JSP和Struts2的模板

2011-04-04 00:49 387 查看
myeclipse版本是6.5,安装在d:/Program/MyEclipse 6.5

1 新增jsp模板
在D:/Program/MyEclipse 6.5/myeclipse/eclipse/plugins/com.genuitec.eclipse.wizards_6.5.0.zmyeclipse650200806/templates/jsp目录下找到Jsp.vtl,复制一份,重命名为jsp2.vtl,然后把里面的内容修改为自己想要的格式,保存。
然后在 D:/Program/MyEclipse 6.5/myeclipse/eclipse/plugins/com.genuitec.eclipse.wizards_6.5.0.zmyeclipse650200806 目录下找到templates.xml,用文本编辑器打开。在
<template
context="com.genuitec.eclipse.wizards.jsp"
script="templates/jsp/Jsp.vtl"
name="Default JSP template"/>
下面增加
<template
context="com.genuitec.eclipse.wizards.jsp"
script="templates/jsp/jsp2.vtl"
name="JSP2 template"/>
保存。重启eclipse。
新建jsp,在模板中就会出现JSP2 template,选中,按完成,新建的jsp页面就按你的模板生成了!

2新增Struts2模板
同理找到D:/Program/MyEclipse 6.5/myeclipse/eclipse/plugins/com.genuitec.eclipse.wizards_6.5.0.zmyeclipse650200806/templates/jsp新建一个Struts2.tvl文件
代码如下
#*---------------------------------------------#
# Template for a Struts2
# @version: 1
#---------------------------------------------#
*#<%@ page language="java" pageEncoding="$encoding"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>'$title'</title>

#parse( "templates/jsp/JSPMetaTags.vtl" )
</head>

<body>
<s:debug/>
</body>
</html>
在templates.xml中找到
<template
context="com.genuitec.eclipse.wizards.jsp"
script="templates/jsp/Struts-1_2-form.vtl"
name="Standard JSP using Struts 1.2/1.3 with a form"/>
紧跟其后添加
<template
context="com.genuitec.eclipse.wizards.jsp"
script="templates/jsp/Struts2.vtl"
name="Standard JSP using Struts2"/>
至此模板新建结束。
注意:
1.D:/Program/MyEclipse 6.5/ 是安装myeclipse的路径。
2.com.genuitec.eclipse.wizards_6.5.0.zmyeclipse650200806中的wizards_6.5.0.zmyeclipse650200806根据版本的不同可能会不同,如可能为com.genuitec.eclipse.wizards_6.0.0.zmyeclipse60020070820等。

一般情况我们只需修改模版信息即可,例如修改JSP页面文件头信息

*#<%@ page language="java" import="java.util.*" pageEncoding="$encoding"%>

改为 *#<%@ page contentType="text/html; charset=$encoding"%>

使用方法:
1选择功能菜单



2 新建页面向导



3查看页面



适合自己的模板能帮助开发人员节省很多时间,经过以上模板优化这样做可以简化我们的开发,提高效率了.

转帖:http://hi.baidu.com/passedbylove/blog/item/743189b3353605b4d9335ae2.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: