yEclipse官方最新版免费下载|Myeclipse汉化下载.MyEclipse-功能最全面的Java IDE. - MyEclipse官方中文网
如果您有HTML或JSP文件要编辑,这里将介绍如何编辑。查找以下信息:
该功能在MyEclipse中是可用的。
要编辑HTML或JSP文件,请执行以下操作当中的一个:
HTML编辑器有以下模式:
打开文件时,默认模式是Design(设计),通过单击编辑器底部的适当选项卡来更改模式。
本文概述了使用源代码编辑器编辑HTML时最重要的概念和特性。
用户可以从源代码模式或设计模式访问源代码,设计模式具有双面板视图,设计模式位于顶部面板,源模式位于底部面板。
直接编辑源代码时,可以使用以下功能:
在整个源代码中,编辑器提供特定于内容的代码帮助。
Tag names(标记名称):Code assist根据当前上下文提供可用HTML标记的列表。
Tag attributes(标记属性):代码辅助提供了特定于正在编辑的标记属性列表。
Attribute values(属性值):在适当的时候,代码帮助会为您提供一个已知可能值的列表。
有两种类型的HTML验证:“输入时”和“资源更改”。
“输入时”:当对HTML文档进行更改时,编辑器总是检查HTML语法的有效性,就像Java编辑器一样。
注意:这种类型的验证错误和警告不会出现在Problems视图中。
资源更改:当资源被修改(保存、移动、复制或导入)时,资源构建器将对资源执行HTML验证。
注意:您可以通过从菜单中选择Window>Preferences,展开MyEclipse并选择Validation来设置验证参数。
要快速格式化源代码,请右键单击编辑器,并选择Source>Format。格式化器不会在内部修改HTML标记元素,它只调整HTML元素的缩进和间距。
使用Cleanup Document选项进行高级格式化和样式调整,允许您更改标记名称和属性的大小写,还有其他选项可以插入所需的标记和属性。要使用此选项,请在编辑器中右键单击并选择Source>Cleanup Document,选择Format source复选框,来将Format Document操作作为文档清理的一部分。
1),模板modify_jsp.ftl文件
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String childPath=request.getContextPath();
String basePath=request.getScheme()+"://"
+request.getServerName()+":"+request.getServerPort()+ childPath +"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<%@ include file="/pub/scripts.jsp"%>
<script type="text/javascript">
function submit_save() {
var varName_=$("#name_").val();
if(varName_==null || varName_=='') {
alert("请先输入名称!")
return false;
} else {
$("#modifyForm").submit();
}
}
// 循环字段集,名称字符与元素id获取元素
<#list mapDataList as listItm >
美元符("井号${listItm.columnName}").val() 双斜杆 ${listItm.columnComment}
</#list>
</script>
</head>
<body>
<!-- 标题区域 -->
<div class="tleBg">
<div class="title">
<span class="txt"> <em></em><#list mapDataTableComment as listItmCom > ${listItmCom.columnComment} </#list>- 修改
</span> <a href="javascript:;" class="search-hide"></a>
</div>
<div class="clr"></div>
</div>
<!-- 查询维度区域 -->
<div class="t_list" id="addtable">
<form name="modifyForm" id="modifyForm" action="<%=childPath %>/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Conter/<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>ModifySave" method="post">
<input type="hidden" name="tid" value="美元符左大括<#list mapDataTableComment as listItmCom > ${listItmCom.columnName} </#list>Dto.tid右大括" />
<table border="0" cellspacing="0" width="100%" cellpadding="0" class="t_list_1">
<tbody>
<#list mapDataList as listItm >
<tr style="line-height: 36px;">
<td width="15%">
</td>
<td width="20%" class="text" style="text-align: right;">
${listItm.columnComment}:
</td>
<td>
<input type="text" id="${listItm.columnName}" name="${listItm.columnName}" style="width: 300px;" class="inputStyle" value="美元符左大括${listItm.columnName}Dto.name_右大括" />
</td>
<td width="15%">
</td>
</tr>
</#list>
<tr>
<td width="15%">
</td>
<td width="20%" class="text" style="text-align: right;">
</td>
<td>
<input type="button" id="btn_add" value="保 存" class="t_button_gray" onclick="return submit_save();" />
<input type="reset" id="btn_rest" value="重 置" class="t_button_gray" />
</td>
<td width="15%">
</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>
(2),生成修改jsp文件
public class TestCls {
public static void main(String[] args) throws Exception {
TestCls testCls=new TestCls();
String testT00_po="testT00_user";
String generFileName=testT00_po + "Modify.jsp";
testCls.outTemplate(testT00_po, "用户数据"
, generFileName, "modify_jsp.ftl" );
System.out.println("执行成功!");
}
// 输出到模板
private void outTemplate(String entryInfoPoName, String tableComment
, String templateFileName , String templFileName ) throws Exception {
Configuration configuration=new Configuration();
String templateDir="F:\\xbl\\myResource\\temp_test_";
configuration.setDirectoryForTemplateLoading(new File(templateDir));
Template template=configuration.getTemplate(templFileName);
Map<String, List<EntryInfoPo>> dataMap=new HashMap<String, List<EntryInfoPo>>();
List<EntryInfoPo> listEntryInfo=new ArrayList<EntryInfoPo>();
listEntryInfo=testMetaAddComment();
dataMap.put("mapDataList", listEntryInfo );
// 表注释
dataMap.put("mapDataTableComment", testTableComment(entryInfoPoName, tableComment ));
String generFileDir="F:\\xbl\\myResource\\temp_test_\\gener_file_\\";
File generFile=new File(generFileDir + templateFileName);
if(generFile.exists()) {
generFile.delete();
}
generFile.createNewFile();
Writer outputWriter=new OutputStreamWriter(new FileOutputStream(generFile ) );
// Writer outputWriter=new OutputStreamWriter(System.out );
template.process(dataMap, outputWriter);
System.out.println("输出完成!");
outputWriter.close();
}
// 表注释
private List<EntryInfoPo> testTableComment(String entryInfoPoName, String tableComment) throws Exception {
List<EntryInfoPo> listTableComment=new ArrayList<EntryInfoPo>();
EntryInfoPo entryInfoPo=new EntryInfoPo();
entryInfoPo.setColumnName(entryInfoPoName);
entryInfoPo.setColumnComment(tableComment);
entryInfoPo.setUpperColumnName(firTextUpper( entryInfoPoName ) );
listTableComment.add(entryInfoPo);
return listTableComment;
}
// 首字母大写
private String firTextUpper(String scontext ) {
int textLength=scontext.length();
String sufText=scontext.substring(1, textLength);
String firText=scontext.substring(0, 1);
firText=firText.toUpperCase();
String finText=firText + sufText;
return finText;
}
private List<EntryInfoPo> testMetaAddComment() throws Exception {
List<EntryInfoPo> listEntryInfoPo=new ArrayList<EntryInfoPo>();
Connection connection=getDataBaseConnection();
Statement statement=connection.createStatement();
ResultSet resultSet=statement.executeQuery("show full columns from t00_user ");
while (resultSet.next()) {
String columnComment=resultSet.getString("Comment");
String columnName=resultSet.getString("Field");
columnName=columnName.toLowerCase();
EntryInfoPo entryInfoPo=new EntryInfoPo();
entryInfoPo.setColumnName(columnName);
entryInfoPo.setColumnComment(columnComment);
listEntryInfoPo.add(entryInfoPo);
}
return listEntryInfoPo;
}
private Connection getDataBaseConnection() throws Exception {
// 连接数据库
Class.forName("com.mysql.jdbc.Driver");
String databaseUrl="jdbc:mysql://127.0.0.1:3306/grcdb05?useUnicode=true&characterEncoding=utf8";
Connection connection=DriverManager.getConnection(databaseUrl, "root", "root");
return connection;
}
}
(3),注意替换空格及替换文字
jsp是一种基于文本的程序,全名java server page,其特点是html和java程序共存。执行时jsp会被运行容器编译,编译后的jsp跟servlet一样,因此jsp是另一种形式的servlet。
jsp 页面包括以下内容:
静态内容
指令
表达式
小脚本
声明
注释
1.指令:
page指令: 通常位于jsp页面的顶端,同一个页面可以有多个page指令。
include指令:将一个外部文件嵌入到jsp文件中。
taglib指令 :使用标签定义新的自定义标签。
1.1其中page指令语法:
<%@ page 属性=“属性值”>
属性 | 默认值 |
---|---|
language | java |
import | “” |
1.2 include 指令
<%@ include file="url" %>
1.3 动作
include动作
<jsp:include page="url" flush="true"/>
include 动作和include指令区别
描述 | include指令 | include 动作
--- | --- | ---
语法 | < % @ include file=""/> | < jsp:include page="url" flush="true"/>
发生时间 | 页面转换期间 | 请求期间
包含内容 | 文件实际内容 | 页面的输出
转化servlet | 一个servlet | 2个servlet
编译时间 | 较慢 | 较快
执行时间 | 稍快 |较慢--每次资源必须被编译
forward动作
<jsp:forward page="url"/>
==request.getRequestDispatcher("/url").forward(res,resp);
param动作
<jsp:param name="参数名" value="参数值"/>常常与<jsp:forward>一起使用
例子:
<jsp:forward page="user.jsp">
<jsp:param name="email" value="1233@154.com"/></jsp:forward>
2.jsp注释
html注释
<!-- html注释 -->//客户端可见
jsp 注释
<%-- jsp注释 --%>//客户端不可见
jsp 脚本注释 //客户端不可见
//单行注射
/** 多行注释*/
3.jsp脚本
在jsp页面中执行的java代码,语法:
<% java 代码 %>
4.jsp声明
在jsp页面定义变量或者方法,语法
<%! java 代码 %>
举例:
<%!
String s="adele"; int add(int x,int y){ return x+y;
}
%>
5.jsp表达式
在jsp页面执行的表达式,语法:
<%=表达式 %>// 表达式不以分号结尾
举例:
<%!
String s="adele";%><h2> hello,<%=s %> </h2>
CC36B22A-503E-4C29-98BB-3B58038C140E.png
jspService()是用来处理客户端请求的,对于每一个请求,服务器会创建一个新的线程来处理该请求。以多线程方式执行大大降低对系统的资源需求,提高系统的并发量和缩短了响应时间,servlet是常驻在服务器内存中。
它同servlet 一样,jsp 实例初始化和销毁也会调用sevlet的init() 和destroy();
另外jsp还有自己的初始化方法_jspInit();_jspDestroy();
<%@ page language="java" contentType="text/html";charset="utf-8">
<%!
public void _jspInit(){
}public void _jspDestroy(){
}
%>
动作元素:
动作元素为请求处理阶段提供信息。
Paste_Image.png
在jsp页面使用javaben
像普通的java类一样,创建javabean;
在jsp使用动作标签来使用 javaben
相关标签如下:
<jsp:useBwan id="" class="" scope="" />
<jsp:setProperty name="javabean 是例" property="*"/>(跟表单关联)
<jsp:setProperty name="javabean 是例" property="javaben 属性名"/>(跟表单关联)
<jsp:setProperty name="javabean 是例" property="javaben 属性名" value=""/>(手动设置)
<jsp:setProperty name="javabean 是例" property="javaben 属性名" param="request对象参数"/>(跟request参数关联)
<jsp:getProperty name="" property=""/>
举个例子:
首先用户 在login.jsp提交表单,然后用户在dologin.jsp 根据动作标签获取参数。
login.jsp
<form name="loginForm" action="dologin.jsp?mypass=999999" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value=""/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" value=""/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录"/></td>
</tr>
</table>
</form>
dologin.jsp
<body>
<jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
<h1>setProperty动作元素</h1>
<hr>
<!--根据表单自动匹配所有的属性 -->
<%--
<jsp:setProperty name="myUsers" property="*"/>
--%>
<!--根据表单匹配所有部分的属性 -->
<%--
<jsp:setProperty name="myUsers" property="username"/>
--%>
<!--根表单无关,通过手工赋值给属性 -->
<%--
<jsp:setProperty name="myUsers" property="username" value="lisi"/>
<jsp:setProperty name="myUsers" property="password" value="888888"/>
--%>
<!--通过URL传参数给属性赋值 -->
<jsp:setProperty name="myUsers" property="username"/>
<jsp:setProperty name="myUsers" property="password" param="mypass"/>
<!-- 使用传统的表达式方式来获取用户名和密码 -->
<%--
用户名:<%=myUsers.getUsername() %><br>
密码:<%=myUsers.getPassword() %><br>
--%> <!-- 使用getProperty方式来获取用户名和密码 -->
用户名:<jsp:getProperty name="myUsers" property="username"/> <br>
密码:<jsp:getProperty name="myUsers" property="password"/><br>
<br>
<br>
<a href="testScope.jsp">测试javabean的四个作用域范围</a>
<%
request.getRequestDispatcher("testScope.jsp").forward(request, response); %>
</body>
javaben 四大作用域
page ,仅当前页面有效
request ,通过httpRequest.getAttribute()获取jvabean对象
session ,通过httpSession.getAttribute() 获取javabean对象
application,通过application.getAttribute方法获取javabean 对象。
1.概述:
由于http协议的无状态,无法保存用户的状态,所以需要用session和cookie.
cookie 是web服务器保存在客户端的一系列文本信息。它的作用时记录一些用户的行为,简化登陆,但是容易泄露用户信息。
2.jsp创建和使用cookie
创建cookie
Cookie cookie=new Cookie(String ,Object);
写入cookie
response.addCookie(cookie);
读取 cookie
Cookie[] cookies=request.getCookies();
3.cookie的常用方法
setMaxAge();
setValue();
getName();
getValue();
getMaxAge();
举个列子: 使用cookie记住用户登陆的账号密码;
登陆界面:
<body>
<h1>用户登录</h1>
<hr>
<%
request.setCharacterEncoding("utf-8");
String username="";
String password="";
Cookie[] cookies=request.getCookies(); if(cookies!=null&&cookies.length>0)
{ for(Cookie c:cookies)
{ if(c.getName().equals("username"))
{
username=URLDecoder.decode(c.getValue(),"utf-8");
} if(c.getName().equals("password"))
{
password=URLDecoder.decode(c.getValue(),"utf-8");
}
}
} %>
<form name="loginForm" action="dologin.jsp" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="username" value="<%=username %>"/></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password" value="<%=password %>" /></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="isUseCookie" checked="checked"/>十天内记住我的登录状态</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登录"/><input type="reset" value="取消"/></td>
</tr>
</table>
</form>
</body>
处理登陆逻辑的jsp
<body>
<h1>登录成功</h1>
<hr>
<br>
<br>
<br>
<%
request.setCharacterEncoding("utf-8"); //首先判断用户是否选择了记住登录状态
String[] isUseCookies=request.getParameterValues("isUseCookie"); if(isUseCookies!=null&&isUseCookies.length>0)
{ //把用户名和密码保存在Cookie对象里面
String username=URLEncoder.encode(request.getParameter("username"),"utf-8"); //使用URLEncoder解决无法在Cookie当中保存中文字符串问题
String password=URLEncoder.encode(request.getParameter("password"),"utf-8");
Cookie usernameCookie=new Cookie("username",username);
Cookie passwordCookie=new Cookie("password",password);
usernameCookie.setMaxAge(864000);
passwordCookie.setMaxAge(864000);//设置最大生存期限为10天
response.addCookie(usernameCookie);
response.addCookie(passwordCookie);
} else
{
Cookie[] cookies=request.getCookies(); if(cookies!=null&&cookies.length>0)
{ for(Cookie c:cookies)
{ if(c.getName().equals("username")||c.getName().equals("password"))
{
c.setMaxAge(0); //设置Cookie失效
response.addCookie(c); //重新保存。
}
}
}
} %>
<a href="users.jsp" target="_blank">查看用户信息</a>
</body>
使用cookie获取用户信息:
<body>
<h1>用户信息</h1>
<hr>
<%
request.setCharacterEncoding("utf-8");
String username="";
String password="";
Cookie[] cookies=request.getCookies(); if(cookies!=null&&cookies.length>0)
{ for(Cookie c:cookies)
{ if(c.getName().equals("username"))
{
username=URLDecoder.decode(c.getValue(),"utf-8");
} if(c.getName().equals("password"))
{
password=URLDecoder.decode(c.getValue(),"utf-8");
}
}
} %>
<BR>
<BR>
<BR>
用户名:<%=username %><br>
密码:<%=password %><br>
</body>
3.cookie和 session的区别
session | cookie |
---|---|
在服务端保存信息 | 在客户端保存信息 |
保存的 object类型 | 保存的是 string 类型 |
随会话结束,销毁数据 | 可以长期保存在客户端中 |
重要信息 | 不重要信息 |
*请认真填写需求信息,我们会在24小时内与您取得联系。