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小時內與您取得聯系。