自定義函數庫
1 定義類和方法(方法必須是public static)
package com.bjsxt.struts;
public class MyFunctios{
public static String sayHello(String name){
return "Hello "+name;
}
}
2 編寫自定義tld文件,并且將此文件放在WEB-INF或WEB-INF的任意子目錄下
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>my functions library</description>
<display-name>my functions</display-name>
<tlib-version>1.0</tlib-version>
<short-name>my</short-name>
<uri>http://www.bjsxt.com/functions</uri>
<function>
<name>say</name>
<function-class>com.bjsxt.struts.MyFunctions</function-class>
<function-signature>java.lang.String sayHello(java.lang.String)</function-signature>
</function>
</taglib>
3 在web.xml中注冊(建意,可以不注冊)
<jsp-config>
<taglib>
<taglib-uri>http://www.bjsxt.com/functions</taglib-uri>
<taglib-location>/WEB-INF/my.tld</taglib-location>
</taglib>
</jsp-config>
4 在JSP中采用taglib指令引入自定義函數庫
<%@ taglib prefix="my" uri="com.bjsxt.struts.MyFunctions"%>
5 調用
${my:say("jack")}
posted @
2009-11-29 22:30 junly 閱讀(457) |
評論 (0) |
編輯 收藏
定制標記庫
1 編寫標記處理類
public class TimerTag extends TagSupport{
private long start;
private long end;
public int doStartTag(){ //doStartTag標記開始方法
start=System.currentTimeMillis();
return EVAL_BODY_INCLUDE;//
}
public int doEndTag() throws JspTagException {//doEndTag標記結束方法
end=System.currentTimeMillis();
long elapsed=end-start;
try{
JspWriter out=pageContext.getOut();
out.println("running time:"+elapsed+"ms.");
}catch(IOException e){
throw new JspTagException(e);
}
return EVAL_PAGE;//
}
}
2 編寫.tld文件
<?xml version="1.0" encoding="UTF-8"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>custion web utility tags</description> //對當前標記庫的描述
<tlib-version>1.0</tlib-version> //當前標記庫的版本
<short-name>util</short-name> //對當前標記庫使用時的前綴名稱
<uri>http://163.com</uri> //可任意
<tag>
<description>calc code running time</description> //對當前標記的描述
<name>timer</name> //標記我名稱
<tag-class>com.tags.TimerTag</tag-class> 當前標記對應的處理類的具體名稱
<body-content>JSP</body-content> //可有empty,JSP
</tag>
</taglib>
3 使用格式
jsp頁面
<%@ taglib prefix="util" uri="http://163.com" %> 添加指令
<util:timer></util:timer>
總結:
TLD是一個XML文件,在WEB-INF目錄下
<taglib>根元素
<tlib-version>version</tlib-version>標記庫的版本
<short-name>prefix</short-name>前綴名稱
<uri>uri</uri>引用的地址
...
<tag>
<name>tagname</name>標記名稱
<tag-class>classname</tag-class>標記對應的處理類
<tei-class>classname</tei-class>標記處理類的輔助處理類
<body-content>[JSP,empty,scriptless,tagdependent]</body-content>
//jsp表示標記中可以包含html,java代碼,這些代碼可以被運行
//empty表示標記中不包含內容
//scriptless表示標記中可以包含EL,jsp的動作代碼,不可以包括JAVA腳本代碼
//tagdependent表示標記中可以包含
<attribute>標記的屬性
<name>pattern</name>屬性的名稱
<required>false</required>表示該屬性是否是必須的
<rtexprvalue>false</rtexprvalue>該屬性是否可以是JSP的表達式
</attribute>
</tag>
</taglib>
TagSupport運行原理(不能對標記所包含的內容進行二次加工)

BodyTagSupport運行原理(可以對開始和結束標記所包含的內容進行處理)
public int doAfterBody()throws JspTagException{
BodyContent bc=getBodyContent();取內容
String input=bc.getString();取內容
JspWriter out=bc.getEnclosingWriter();
String newContent=input;
try{
out.println(newContent);
}catch(IOException e){
throw new JspTagException(e);
}
return 1;
}
posted @
2009-11-29 22:29 junly 閱讀(1499) |
評論 (0) |
編輯 收藏
Tag Library JAR
標記庫打包
1 前建一個臨時文件temp
2 把當前工作空間下的classes文件夾下的文件復制到temp文件夾下
3 在temp文件夾下新建WEB-INF文件夾
4 把當前項目下的WEB-INF目錄下的.tld文件復到到temp中WEB-INF文件夾下
5 啟用DOS,進入temp目錄下
6 運行命令:jar -cvf mytags.jar *
mytags為要生成的jar文件名
*代表temp文件下的所有文件
7 其他項目要用時將該jar文件復制到項目的lib目錄下就可以了
開源定制標記庫
JSTL
Jakarta Taglibs http://jakarta.apache.org/taglibs/index.html
Display tag http://displaytag.sf.net
posted @
2009-11-29 22:20 junly 閱讀(207) |
評論 (0) |
編輯 收藏
JSTL
------------------------------------------------------------------------------
功能領域 URI 前綴 描述
Core http://java.sun.com/jsp/jstl/core c 核心標記庫
format http://java.sun.com/jsp/jstl/fmt fmt 格式化標記庫-進間、日期、國際化
SQL http://java.sun.com/jsp/jstl/sql sql 對數據庫的操作
XML http://java.sun.com/jsp/jstl/xml xml 對XML的操作
Functions http://java.sun.com/jsp/jstl/functions fn 函數標記庫,主要是字符串
用在視圖層的技術
--------------------------------------------------------------------------------
用使:
1 引用標記庫
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
用戶名:<c:out value="${username}" />
</body>
</html>
-----------------------------------------------------------------------------------
Core核心標記庫
操作變量 條件操作 循環操作 URI操作
out if forEach import
set choose forTokens url
remove when redirect轉向
catch otherwise param
--------------------------------------------------------------------------------------
<c:out>標記
使用語法
1 <c:out value="vlaue" [escapeXml="{true|false}"]
[default="defaultValue"] />
2 <c:out value="vlaue" [escapeXml="{true|false}"]>
default value
</c:out>
屬性
------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 缺省值
value | 需要輸出的值,可以是EL表達式或常量 | 可以 | 是 | 無
default | value值為空時所輸出的內容 | 可以 | 否 | 無
escapeXml | 為true對輸出內容中的<、>、'、"和& | 可以 | 否 | true
| 字符進行轉義,分別轉成都市<,>, | | |
| ',"和&.為false不進行轉義 | | |
------------------------------------------------------------------------
<c:set>標記
使用語法
1 <c:set value="value" var="name" [scope="{page|request|session|application}"] />
2 <c:set var="name" [scope="{page|request|session|application}"]>
value
</c:set>
3 <c:set var="name" target="target" property="propertName">
4 <c:set target="target" propert="propertyName">
value
</c:set>
3和4是給已有的對象屬性賦值
屬性
-----------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 缺省值
value | 要保存的內容,可以是EL表達式或常量 | 可以 | 是 | 無
target | 要修改屬性的對象名,一般為javaBeans對象名 | 可以 | 否 | 無
property | 要修改的javaBeans的屬性 | 可以 | 否 | 無
var | 要保存內容的變量名 | 否 | 是 | 無
scope | 保存內容的變量的作用范圍 | 否 | 否 | page
-----------------------------------------------------------------------------
<c:remove>標記
使用語法
<c:remove var="name" [scope="{page|request|session|application}"] />
屬性
------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 缺省值
var | 被刪除的變量的名字 | 否 | 是 | 無
scope | 被刪除的變量的作用范圍 | 否 | 否 | page,request,session,application
------------------------------------------------------------------------------------------------
<c:catch>標記
使用語法
<c:catch [var="name"]>
body content
</c:catch>
屬性
------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 缺省值
var | 用來保存違例信息的變量名 | 否 | 否 | 無
------------------------------------------------------------------------
例子:
<c:catch var="ex">
<%
String number="none";
int i=Integer.parseInt(number);
%>
</c:catch>
${ex}
將違例信息保存在ex變量中,如沒有發生違例,則什么也不作
<c:if>標記
使用語法
1 <c:if test="condition" var="name" [scope="{page|request|session|application}"] />
2 <c:if test="condition" [var="name"] [scope="{page|request|session|application}"]>
body content
</c:if>
屬性
-----------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 缺省值
test | 判斷所要使用的條件 | 可以 | 是 | 無
var | 保存條件結果的變量的名稱 | 否 | 否 | 無
scope | 保存條件結果的變量的作用范圍 | 否 | 否 | page
-----------------------------------------------------------------------------
<c:choose>標記
使用語法
<c:choose>
body content(<when>and<otherwise>)
</c:choose>
<c:when>標記
使用語法
<c:when test="condition">
body content
</c:when>
屬性
-----------------------------------------------------------------------------
屬性名 | 描述 | 動態 | 必選 | 缺省值
test | 如果它的結果為true,執行<c:when>所包含的 | 可以 | 是 | 無
| 內容,false則不執行<c:when>所包含的內容 | | |
-----------------------------------------------------------------------------
<c:otherwise>標記
使用語法
<c:otherwise>
body content
</c:otherwise>
---------------------------------------------------------------------------
例子:
<c:choose>
<c:when test="${param.age>=70}">
70以上
</c:when>
<c:when test="${param.age>35 and param.age<70}">
35-70
</c:when>
<c:otherwise>
35以下
</c:otherwise>
</c:choose>
--------------------------------------------------------------------------------------------
<c:forEach>標記
使用語法
1 <c:forEach [var="name"] items="collection" [varStatus="varStatusName"]
[begin="begin"] [end="end"] [step="step"]>
body content
</c:forEach>
2 <c:forEach [var="name"] items="collection" [varStatus="varStatusName"]
begin="begin" end="end" [step="step"]>
body content
</c:forEach>
屬性
------------------------------------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 類型 |缺省值
begin | 開始下標 | 可以 | 否 | int |0
end | 結束下標 | 可以 | 否 | int |集合中最后一個成員的索引
step | 步長 | 可以 | 否 | int |1
var | 代表當前成員的變量名 | 否 | 否 | String |無
items | 進得循環的集合 | 否 | 否 | String,數組,Map,Collection,Iterator,Enumeration |無
varStatus | 顯示循環狀態的變量 | 可以 | 否 | String |無
-------------------------------------------------------------------------------------------------------------------------------
varStatus屬性
----------------------------------------------------------
名稱 | 類型 | 描述
index | int | 現在所操作的成員的索引
count | int | 現在所操作的成員的總數
first | boolean | 現在所操作的成員,是否為第一個成員
last | boolean | 現在所操作的成員,是否為最后一個成員
----------------------------------------------------------
<%
String names[]=new String[4];
names[0]="afdsaf";
names[1]="dggh";
names[2]="bcbncn";
names[3]="434535";
pageContext.setAttribute("names",names);
Map map=new HashMap();
map.put("k1","v1");
map.put("k2","v2");
request.setAtrribute("map1",map);
%>
<c:forEach items="${names}" var="name" begin="1" end="2" step="1" varStatus="i">
${name } ${i.index } ${i.count } ${i.first } ${i.last }<br/>
</c:forEach>
<c:forEach items="${map1}" var="v">
${v.key } = ${v.value }<br/>
</c:forEach>
<c:forTokens>標記 將一個字符串進行分隔
使用語法
<c:forTokens items="stringOfTokens" delims="delimiters" [var="name"]
[varStatus="varStatusName"] [begin="begin"] [end="end"] [step="step"]>
body content
</c:forTokens>
屬性
------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 | 類型 |缺省值
items | 進行迭代處理的變量 | 可以 | 是 | String |無
delims | 分割符號 | 可以 | 是 | char |無
begin | 開始下標 | 可以 | 否 | int |0
end | 結束下標 | 可以 | 否 | int |集合中最后一個成員的索引
step | 步長 | 可以 | 否 | int |1
var | 代表當前成員的變量名 | 否 | 否 | String |無
varStatus | 顯示循環狀態的變量 | 否 | 否 | String |無
-------------------------------------------------------------------------------------------
<c:forTokens items="dsf:dsafsa:dsffs,dfdfs" var="name" delims=":,">
${name }<br/>
</c:forTokens>
-------------------------------------------------------------------------------------------
<c:import>標記 相當于include將另外一個頁面的內容引入到當前頁面來
使用語法
1 <c:import url="url" [context="context"] [var="name"] [scope="{page|request|session|application}"]
[charEncoding="charEncoding"]>
<c:param>//可傳參數
</c:import>
2 <c:import url="url" [context="context"] varReader="varReaderName"
[charEncoding="charEncoding"]>
body content//內容
</c:import>
屬性
------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
url | 需要導入頁面url地址 | 是 | 是 |無
context | 本地web應用的名字 | 是 | 否 |當前應用的名子
charEncoding | 設置導入數據的字符編碼 | 是 | 否 |ISO-8859-1
var | 接受導入文本的變量的名稱 | 否 | 否 |無
scope | 接受導入文本內容的變量的作用范圍 | 否 | 否 |page
varReader | 用于接受導入文本的java.io.Reader變量的名稱 | 否 | 否 |無
-------------------------------------------------------------------------------------------
<c:url>標記 創建鏈接
使用語法
1 <c:url value="value" [context="context"] [var="name"] [scope="{page|request|session|application}"] />
2 <c:url value="value" [context="context"] [var="name"] [scope="{page|request|session|application}"] />
<c:param />
</c:url>
屬性
------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
value | url地址 | 是 | 是 |無
context | web應用的名字 | 是 | 否 |當前web應用的名子
var | 保存url地址的變量的名稱 | 否 | 否 |輸出到當前頁面
scope | 存儲url地址的變量的作用范圍 | 否 | 否 |page
-------------------------------------------------------------------------------------------
<c:url var="website" value="http://localhost:8080/webproject/out.jsp">
<c:param name="p" value="hello" />
</c:url>
${website }<br>
<a href=" ${website }">dddd</a>
--------------------------------------------------------------------------------
<c:redirect>標記 頁面跳轉
使用語法
1 <c:redirect url="value" [context="context"] />
2 <c:redirect url="value" [context="context"]>
<c:param />
</c:redirect>
屬性
------------------------------------------------------------------------------------------
屬性名 | 描述 | 必選 |缺省值
url | url地址 | 是 |無
context | 要轉向到的web應用的名字 | 否 |當前web應用的名子
-------------------------------------------------------------------------------------------
<c:redirect url="LoopTag.jsp">
<c:param name="p" value="aa" />
</c:redirect>
-------------------------------------------------------------------------------
Format標記庫
-----------------------------------------
國際化有關 | 時間日期有關(一般不在頁面作處理)
setLocale | formatNumber
requestEncoding | formatDate
bundle | parseDate
message | parseNumber
param | setTimeZone
setBundle | timeZone
-----------------------------------------
<fmt:setLocale>標記 設置國際化語言
使用語法
<fmt:setLocale value="locale" [variant="variant"] [scope="{page|request|session|application}"] />
屬性
---------------------------------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
value | 表示該語言環境的一個字符串,或者是java.util.Locale類的對象 | 可以 | 是 |無
scope | 指定這個對象的作用范圍,有效值為page,requset,session,applicattion | 否 | 否 |page
variant | 進一步針對特定的平臺或供應商定制語言環境。如,MAC和WIN分別對應Macintosh和Windows平臺 | 可以 | 否 |無
---------------------------------------------------------------------------------------------------------------------------
<fmt:setBundle>標記 設定國際化資源束的位置
使用語法
<fmt:setBundle basename="basename" [var="name"] [scope="{page|request|session|application}"] />
屬性
---------------------------------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
basename | 設置使用的資源文件束文件的路徑與名稱,不應當包含任保本地化后綴或文件擴展名 | 可以 | 是 |無
var | 設置了該屬性,那么將把basename屬性所標識的資源束賦給該屬性值所命名的變量 | 否 | 否 |無
scope | 指明缺省資源束設置所應用的JSP作用域 | 否 | 否 |page
---------------------------------------------------------------------------------------------------------------------------
束文件名resources_zh_CN.properties(basename屬性)
<fmt:setBundle basename="com.v512.examples.resources" />
<fmt:bundle>標記 設定某個頁面或某幾行國際化資源束的位置
使用語法
<fmt:bundle basename="basename" [prefix="prefix"]>
body content
<fmt:bundle>
屬性
---------------------------------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
basename | 設置使用的資源文件束文件的路徑與名稱,不應當包含任保本地化后綴或文件擴展名 | 可以 | 是 |無
prefix | 為所嵌套的<fmt:message>標記的key值指定缺省前綴 | 可以 | 否 |無
---------------------------------------------------------------------------------------------------------------------------
<fmt:message>標記 (核心)設置資料束文件中的KEY和對應的內容
使用語法
1 <fmt:message key="messageKey" [bundle="resourceBundle"] [var="varName"] [scope="{page|request|session|application}"] />
2 <fmt:message [bundle="resourceBundle"] [var="varName"] [scope="{page|request|session|application}"]>
key
[<fmt:param>]
</fmt:message>
屬性
-----------------------------------------------------------------------------------------------------------------------------------------------
屬性名 | 描述 | EL | 必選 |缺省值
key | 用來確定在資源束中定義哪個文本消息進行輸出顯示 | 可以 | 是 |無
bundle | 用來指定一個顯式的資源束,用來查找由key屬性標識的消息.請注意,該屬性的值必須是實際的資源束. | 可以 | 否 |無
| 如當指定<fmt:setBundle>操作的var屬性時同該標記所賦予的資源束.<fmt:message>的bundle屬性不支持字符串值
var | 該標記所生成的文本消息賦給指定的變量,而不是輸出到JSP頁面中 | 否 | 否 |無
scope | 由來指定的var屬性指定的變量的作用域,有效值:page,request,session,application | 否 | 否 |page
-----------------------------------------------------------------------------------------------------------------------------------------------
<fmt:requestEncoding>標記 設置編碼方式
使用語法
<fmt:requestEncoding [value="charsetName"] />
作用等同于
request.setCharacterEncoding()
--------------------------------------------------------------------------------
<fmt:param>標記 設置編碼方式
使用語法
1 <fmt:param value="messageParameter" />
2 <fmt:param>
body content
</fmt:param>
-----------------------------------------------------------------
<fmt:formatDate> 標記
使用方法:
<fmt:formatDate value="${today}" type="date" />
<fmt:formatDate value="${today}" dateStyle="full" />
<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" />
<fmt:formatDate value="${today}" pattern="yyyy/MM/dd HH:mm:ss" var="d"/>
----------------------------------------------------------------------------
屬性名 | 描述 | 值 |結果
value | 要格式化的日期值 | default |2008-8-1
type | 顯現的日期格式 | date |2008-8-1
| | time |14:47:59
| | both |2008-8-1 14:47:59
dateStyle | 顯現的日期格式 | short |08-8-1
| | medium |2008-8-1
| | long |2008年8月1日
| | full |2008年8月1日 星期一
pattern | 定義日期格式 |yyy/MM/dd HH:mm:ss |2008/08/01 14:47:59
var | 保存值變量名 | |
scope | 保存變量的scope | |
-----------------------------------------------------------------------------
<fmt:formatNumber> 標記
<fmt:formatNumber value="${n}" pattern="###,###.##"/>
<fmt:formatNumber value="${n}" pattern="###,###.0000"/>
----------------------------------------------------------------------------
屬性名 | 描述 | 值 |結果
value | 要格式化的日期值 | default |123,456.123
type | 顯現的數據格式 | number(數字) |123,456.123
| | currency(貨幣) |¥123,456.123
| | percent(百分比) |23.33%
groupingUsed| 是否分組顯示 | true/false |
pattern | 定義數據格式 |###,###.## |123,456.123
| |###,###.0000 |123,456.1230
var | 保存值變量名 | |
scope | 保存變量的scope | |
-----------------------------------------------------------------------------
<format>標記例子
1 建立resources.properties文件(英文)
內容:guestbook.display.welcome=welcome to my website
2 建立resources.properties_zh_CN.properties文件(中文)
方法:
(1)在臨時目錄下建立一個臨時文件resources_t.properties
內容:guestbook.display.welcome=歡迎大家訪問網站
(2)在DOS下進行該臨時目錄,執行DOS命今
c:\temp>native2ascii -encoding uft-8 resources_t.properties resources_zh_CN.properties
(3)將轉換好的文件復制到項目目錄下
3 建立JSP頁面
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
fmt:bundle basename="com.tags.resources">
<fmt:message key="guestbook.display.welcome">
</fmt:message>
</fmt:bundle>
-----------------------------------------------------------------------------------------------------------
<sql>標簽
<setDatasource>
<update>
<query>
<param>
1 導入sql的jar包
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<sql:setDataSource driver="" url="" user="" password="" var="" scope=""/>
<sql:update var="oerder" dataSource="${conn}">
insert into BookOrder(username,zipcode,phone,creditcard,total)
values(?,?,'88888833333','123432432423',50.00)
<sql:param value="accp"/>
<sql:param value="1111"/>
</sql:update>
<sql:query var="rs" dataSource="${conn}">
select * from aa
</sql:query>
<C:forEach var="row" items="${rs.rows}">
${row.username} ${row.password}
</c:forEach>
posted @
2009-11-29 22:19 junly 閱讀(336) |
評論 (0) |
編輯 收藏
jsp:include
<jsp:include page="/include.jsp"></jsp:include>動作
<%@ include file="/footer.html"%>//指今
jsp:forward
1 <jsp:forward page="/include.jsp" />
2 <%
RequestDispatcher rd=request.getRequestDispatcher("/imclude.jsp");
rd.forward(request,response);
%>
1和2結果相同
posted @
2009-11-29 22:04 junly 閱讀(211) |
評論 (0) |
編輯 收藏
javaBean
* 封裝數據
* 封裝業務方法
<jsp:useBean/>
<jsp:useBean id="" class="" scope=""/>
class屬性必須打包,scope默認為page
<jsp:setProperty/>
<jsp:setProperty name="user" property="*"/>
多個form屬性自動匹配
<jsp:getProperty/>
<jsp:forward/>
<jsp:forward page="b.jsp"/>//相當于request.getRequestDispatcher
<jsp:include/>
區分大小寫
posted @
2009-11-29 22:03 junly 閱讀(202) |
評論 (0) |
編輯 收藏
//EL 的基本用法
類型 | 示例 | 對應的調用方法
javaBeans | ${user.username}* | user.getUsername()
| ${user["username"]} |
| ${user['username']} | sport[1]
數組 | ${sport[1]}* |
| ${sport['1']} |
| ${sport["1"]} |
List | ${address[2]}* | address.get(2)
| ${address['2']} |
| ${address["2"]} |
Map | ${phone["home"]} | phone.get("home")
| ${phone['home']} |
| ${phone.home}* |
//EL的內置對象(與JSP有區加別,只能在EL中使用,不能用在JSP中,名稱不同但指同一個內容)
pageContext 對應JSP中當前頁面上下文的對象
pageScope 對應JSP中page對象
requestScope 對應JSP中request對象
sessionScope 對應JSP中session對象
applicationScope 對應JSP中application對象
param 對應頁面傳值的對象
paramValues 對應頁面傳來一組值的對象
header 對應頁面頭信息的值對象
headerValues 對應頁面頭信息的數組對象
<%= session.getAttribute("phone")%>
等價于:
${sessionScope.phone}
cookie對應cookie對象的值
initParam對應設定的初始參數的值
//設定JSP不使用JSP EL
當前面頁不使用
<%@page isELIgnored="true"%>
整個WEB應用不使用JSP EL
修改web.xml
<web-app...>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
</web-app>
----------------------------------------------------
pageContext.setAttribute("username",null)//false
pageContext.setAttribute("username","")//false
${empty username}//判斷username是否為空
---------------------------------------------------
pageContext.setAttribute("username","janly")
request.setAttribute("username","janly")
session.setAttribute("username","janly")
application.setAttribute("username","janly")
${pageScope.username}
${requestScope.username}
${sessionScope.username}
${applicationScope.username}
${username}按作用域范圍找查
-----------------------------------------
web.xml
<context-param>
<param-name>repeat</param-name>
<param-value>100</param-value>
</context-param>
${initParam.repeat}
${param.username}
---------------------------------
posted @
2009-11-29 22:02 junly 閱讀(198) |
評論 (0) |
編輯 收藏
一 導包
二 在WEB-INF下加配置文件persistence.xml
1 提供者
2 類
3 數據庫
三 在實體類中加JPA注記
@Enttity
@Table(name="t_user")
public class Users{}
主鍵標在get方法前
@Id
@GeneratedValue(strategy=GenerationType.AUTO[IDENTITY])
@Column(name="d")
public int getId(){}
關系
@OneToOne(cascade="")
@OneToMany()
private Set users=new HashSet();
import javax.
@Test public void testMM(){
EntityManagerFactory emf=Persistence.createEntityManagerFactory("配置文件中jpa名");
EntityManager em=emf.createEntityManager();
//Custems c=em.find(Custems.class,1);
Query query=em.createQuery("");
List<Custems> custems=query.getResultList();
Custems custem=query.getSingleRusult();
EntityTransaction et=em.getTransaction();
te.begin();
em.persist(new Custems());//加
em.setCname("aaa");
em.merge(custems);//修改
em.remove(custems);//刪
te.commit();
}
-------------------------------------------------------
JpaDaoSupport
<bean id="dao" class="org.my doa.CustemsDao">
<property name="entityManagerFactiory" ref=""/>
</bean>
posted @
2009-11-29 21:58 junly 閱讀(227) |
評論 (0) |
編輯 收藏
<script type=text/javascript>
<!--
function MyImageA()
{
document.all.MyPic.src="C:\Documents and Settings\All Users\Documents\My Pictures\示例圖片\Sunset.jpg";
}
function MyImageB()
{
document.all.MyPic.src="C:\Documents and Settings\All Users\Documents\My Pictures\示例圖片\Blue hills.jpg";
}
-->
</script>
<img name=MyPic id="MyPic " src="C:\Documents and Settings\All Users\Documents\My Pictures\示例圖片\Sunset.jpg" width=300 height=200></img>
<script type=text/javascript>
document.all.MyPic.onmouseover=MyImageA;
document.all.MyPic.onmouseout=MyImageB;
</script>
posted @
2009-11-29 21:55 junly 閱讀(283) |
評論 (0) |
編輯 收藏
<script language="javascript">//arguments對象(參數對象)
///arguments對象(參數對象)
function testParams()
/*{
var params="";
for(var i=0;i<arguments.length;i++)
{
params+=" "+arguments[i];
}
alert(params);
}
testParams("abc",123);
testParams(123,456,"abc");*/
</script>
<script language="javascript">//創建動態函數
///創建動態函數
//var square=new Function("x","y","var sum;sum=x*x+y*y;return sum;");
//等同于
/*function square(x,y)
{
return x*x+y*y;
}
alert(square(2,3));*/
//encodeURI方法(url字符編號)
/*var urlStr = encodeURI("http://www.it315.org/imdex.html?country=中國&name=z x");
alert(urlStr);*/
//decodeURI方法(對已編號的url進行解號)
/*urlStr = decodeURI("http://www.it315.org/imdex.html?country=%E4%B8%AD%E5%9B%BD&name=z%20x");
alert(urlStr);*/
//parseInt方法
//parseFloat方法
//isNaN方法
//escape方法(對一個字符進行Unicode編號)
//unescape方法(解碼)
//eval方法(將其中的參數字符串作為一個javascript表達式執行,可以動態產生表達式)
</script>
<script language="javascript">//對象與對象實例
///對象與對象實例
/*function Person()//Person對象的構造函數---構造函數
{}
var person1=new Person();//創建Person對象的實例---對象實例
person1.age=18;//為對象實例添加成員,可以對其無限制的添中新的成員
//person1.age也可以用person1["age"]訪問,這樣可以動態訪問其成員
person1.name="abb";//---屬性
//alert(person1.name+":"+person1.age);
function sayFunc()
{
alert(person1.name+":"+person1.age);
//alert(person1["name"]+":"+person1["age"]);
//var x="name";
//alert(person1[x]+":"+person1["age"]);
//x="age";
//alert(person1[x]+":"+person1["age"]);
//eval("alert(person1.name);");與下面結果相同
//alert(person1.name);
//var x="age";
//eval("alert(person1."+x+");");
}
person1.say=sayFunc;//---方法(函數指針) 不能為person1.say=sayFunc();
person1.say();*/
</script>
<script language="javascript">//構造方法與this關鍵字
///構造方法與this關鍵字
//為一個對象實例新增加屬性和方法,不會增加到同一個對象所產生的其它對象實例上
/*function Person(name,age)
{
this.age=age;
this.name=name;
this.say=sayFunc;
}
function sayFunc()
{
alert(this.name+":"+this.age);
//alert(name+":"+this.age);//錯誤,this不能去掉
}
var person1=new Person("張三",18);
person1.say();
var person2=new Person("李四",20);
person2.say();*/
</script>
<script language="javascript">//在函數中修改參數值的問題
///在函數中修改參數值的問題
//值傳寄
/*function changeValue(x)
{
x=5;
}
var x=3;
changeValue(x);
alert(x);*/ //值仍為3,未修改,值傳寄
//對象傳寄
/*function Person(name,age)
{
this.age=age;
this.name=name;
this.say=sayFunc;
}
function sayFunc()
{
alert(this.name+":"+this.age);
}
function chage(p1)
{
p1.name="王五";
}
var p1=new Person("張三",18);
chage(p1);
p1.say();*/
</script>
<script language="javascript">//javascript內部對象
///javascript內部對象
//動態對象 使用時new實例并用“實例名.成員”的格式訪問--------------------動態對象
//-String對象(屬性length)---是動態地象也是一個特殊的數據類型
//var myStrObj=new String("www.it315.orgit");
//var myStrObj="www.it315.org";//結果同上
//alert("www.it315.org".length);//結果同下
//alert(myStrObj.length);
//-big()方法--原字符兩邊加<big></big>標簽對
//alert(myStrObj.big());
//-bold()方法--原字符兩邊加<b></b>標簽對
//alert(myStrObj.bold());
//-fontcolor()方法--設置字符串的顏色
//alert(myStrObj.fontcolor("red"));
//-anchor()方法--添加超連接標記name屬性
//alert(myStrObj.anchor("re"));
//-link()方法--添加超連接標記scr屬性
//alert(myStrObj.link("www.it315.org"));
//其他方法如bold,italics,blink,small,fontsize
//-charAt()方法--返回索引位的字符,以0開始,超出length-1返回空
//alert(myStrObj.charAt(12));
//-charCodeAt()方法--返回索引位的字符的unicode編號,以0開始,超出length-1返回空
//alert(myStrObj.charCodeAt(12));
//-lastIndexOf()方法--返回某子字符串第一次出現的索引位置,從右向左,沒找到返回-1
//alert(myStrObj.lastIndexOf("it"));
//-indexOf()方法--返回某子字符串第一次出現的索引位置,左向右,沒找到返回-1
//alert(myStrObj.indexOf("it"));
/*var p=myStrObj.indexOf("it")
while(p != -1)
{
alert(p);
p=myStrObj.indexOf("it",pos+1);
}*/
//-match()方法--使用正則表達式檢證字符
//-search()方法--使用正則表達式方法查子串,類似于indexOf
//-replace()方法--替換子串,可用正則
//-split()方法--分隔符取子串生成數組,可用正則
//-slice()方法--返回指定位置之間的字符串,取前不取后
//slice(4,6);slice(4);
//substr(),substring()方法--取子串substring()類似于slice(),substr(開始位置,長度)
//-toUpperCase()小寫轉大寫
//-toLowerCase()大寫轉小寫
//Date對象
//-構造函數Date(),Date(dateVal),Date(year,month,date[,hours[,minutes[,seconds[,ms]]]])
//-parse()方法--靜態方法
//-getYear(),getMonth(),getDate(),getDay(),getHours(),getMinutes(),getSeconds(),getMilisecons()
//-getTime()返回1970-1-1起的毫秒數
//-set方法與get方法對映
//靜態對象 用“對象名.成員”的格式訪問 ----------------------------------靜態對象
//Object對象(提供創建自定義對象的簡單方式,不需要程序員再定義構造函數)
/*function getAttributeValue(attr)
{
alert(person[attr]);
}
var person=new Object();
person.name="zs";
person.age=18;
getAttributeValue("name");
getAttributeValue("age");*/
//Math對象
//-random()方法--返加0-1之間的隨機數,abs()方法
//toString()方法--所有對象都有
</script>
<script language="javascript">//對象專用語句
///對象專用語句
//with語句子--可以一次引用對象實例的屬性或方法
/*var current_time=new Date();
with(current_time)
{
var strDate=getYear()+"年";
strDate+=getMonth()+"月";
strDate+=getDate()+"日";
strDate+=getHours()+":";
strDate+=getMinutes()+":";
strDate+=getSeconds();
alert(strDate);
}*/
//for...in語句-對對象屬性進行操作
/*function Person(name,age)
{
this.age=age;
this.name=name;
}
var p=new Person("lisi",19);
var prep="";
for(prep in p)
{
alert(p[prep]);
}*/
</script>
<script language="javascript">//數組列表--有length屬性能
///數組列表--有length屬性能
/*var arr=["as"+1,321,2.5,"abb",""];//可以是任意數據類型,可以為空或合法表達式
for(var i=0;i<arr.length;i++)
{
alert(arr[i]);
}*/
///用對象的方式實現數組
/*function MyArray()
{
this.length=arguments.length;
for(var i=0;i<this.length;i++)
{
this[i]=arguments[i];
}
}
var str="";
var arr=new MyArray(4,3.5,"abc");
for(var i=0;i<arr.length;i++)
{
str+=i+":"+arr[i]+"\n";
}
alert(str);*/
</script>
<script language="javascript">//Array對象
///Array對象
//-構造方法
//-Array();Array(4);-長度Array(3.5,"abc",3);
/*var arr=new Array();
var x,str="";
arr[0]="abc";
arr[1]=23;
arr[2]=3;
arr.sort();
for(x in arr)
{
str=str+x+":"+arr[x]+"\n";
}
alert(str);*/
</script>
posted @
2009-11-29 21:52 junly 閱讀(421) |
評論 (0) |
編輯 收藏