<?
xml?version="1.0"?encoding="UTF-8"
?>
<!
DOCTYPE?hibernate-mapping?PUBLIC
?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
?"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<
hibernate-mapping
>
??
<
class?
name
="Tuser"
?table
="T_User"
>
????
<
id?
name
="id"
?column
="id"
?type
="java.lang.Integer"
>
??????
<
generator?
class
="native"
/>
????
</
id
>
????
<
property?
name
="name"
?column
="name"
?type
="java.lang.String"
/>
????
<!--
<property?name="age"?column="age"?type="java.lang.Integer"/>
-->
????
<!--
<property?name="email"?column="email"?type="EMailList"/>
-->
????
<!--
<property?name="image"?column="image"?type="java.sql.Blob"/>
-->
????
<
property?
name
="resume"
?column
="resume"
?type
="clob"
/>
??
</
class
>
</
hibernate-mapping
>
復合主鍵
<?xml?version="1.0"?encoding="UTF-8"?>
<!DOCTYPE?hibernate-mapping?PUBLIC
?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
?"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<hibernate-mapping>
??<class?name="TUser2"?table="T_User2">
????<composite-id?name="userPk"?class="TUserPk">
??????<key-property?name="firstName"?column="firstname"?type="java.lang.String"/>
??????<key-property?name="lastName"?column="lastname"?type="java.lang.String"/>
????</composite-id>
????<property?name="age"?column="age"?type="java.lang.Integer"/>????
??</class>
</hibernate-mapping>
DISCRIMINATOR
<?xml?version="1.0"?encoding="UTF-8"?>
<!DOCTYPE?hibernate-mapping?PUBLIC
?"-//Hibernate/Hibernate?Mapping?DTD?3.0//EN"
?"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
>
<hibernate-mapping>
??<class?name="TItem"?table="T_Item">
????<id?name="id"?column="id">
??????<generator?class="native"/>
????</id>
????<discriminator?column="category"?type="java.lang.String"/>
????<property?name="manufacturer"?column="manufacturer"/>
????<property?name="name"?column="name"/>????
????<subclass?name="TBook"?discriminator-value="1">
??????<property?name="pageCount"?column="pagecount"/>
????</subclass>
????<subclass?name="TDVD"?discriminator-value="2">
??????<property?name="regionCode"?column="regionCode"/>
????</subclass>
??</class>
</hibernate-mapping>
<!
DOCTYPE?hibernate-configuration?PUBLIC
????"-//Hibernate/Hibernate?Configuration?DTD?3.0//EN"
????"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
>
<
hibernate-configuration
>
??
<
session-factory
>
????
<
property?
name
="hibernate.connection.url"
>
???????jdbc:Microsoft:sqlserver://192.168.10.236:1433;databaseName=Sample
????
</
property
>
????
<
property?
name
="hibernate.connection.driver_class"
>
???????com.microsoft.jdbc.sqlserver.SQLServerDriver
????
</
property
>
????
<
property?
name
="hibernate.connection.username"
>
???????sa
????
</
property
>
????
<
property?
name
="hibernate.connection.password"
>
???????55
????
</
property
>
????
<
property?
name
="dialect"
>
???????org.hibernate.dialect.SQLServerDialect
????
</
property
>
????
<
property?
name
="hibernate.show_sql"
>
???????true
????
</
property
>
????
<
property?
name
="hibernate.transaction.factory_class"
>
???????org.hibernate.transaction.JDBCTransactionFactory
????
</
property
>
????
<
mapping?
resource
="TItem.hbm.xml"
/>
????
??
</
session-factory
>
</
hibernate-configuration
>
Save
// 新增名為"Emma"的用戶記錄
Tuser user = new Tuser();
user.setName("Emma");
session.save(user);
Get
// 假設T_User表中存在ID = 1的記錄
Tuser user = (Tuser)session.get(Tuser.class, new Integer(1));
Delete
// 假設T_User表中存在ID = 1的記錄
Tuser user = (Tuser)session.get(Tuser.class, new Integer(1));
session.delete(user);
// 也可以通過HQL指定刪除條件
Session.delete(" from Tuser where id = 1");
// 通過Query接口進於基於HQL的刪除操作
Stirng hql = "delete Tuser where id = 1";
Query query = session.createQuery(hql);
query.executeUpdate();
Find
// 通過Query接口進行數據查詢
String hql="from Tuser user where user.name like ?";
Query query = session.createQuery(hql);
query.setParameter(0, "Cartier");
List list = query.list();
Iterator it = list.iterator();
while(it.hasNext()){
? Tuser user = (Tuser)it.next();
? System.out.println(user.getName());
}
// 通過Criteria接口進行數據查詢
Criteria criteria = session.createCriteria(Tuser.class);
criteria.add(Expression.eq("name","Cariter"));
List list = criteria.list();
Iterator it = list.iterator();
while(it.hasNext()){
? Tuser user = (Tuser)it.next();
? System.out.println(user.getName());
}
如何混合使用Jsp和SSI #include?
在JSP中可以使用如下方式包含純HTML:
<!--#include file="data.inc"-->
但是如果data.inc中包含JSP CODE ,我們可以使用:
<%@include file="data.inc"%>
如何執行一個線程安全的JSP?
只需增加如下指令
<%@ page isThreadSafe="false" %>
JSP如何處理HTML FORM中的數據?
通過內置的request對象即可,如下:
<%
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
%>
在JSP如何包含一個靜態文件?
靜態包含如下:<%@ include file="copyright.html" %>
動態包含如下:<jsp:include page="copyright.html" flush="true"/>
在JSP中如何使用注釋?
主要有四中方法:
1。<%-- 與 --%>
2。//
3。/**與**/
4。<!--與-->
在JSP中如何執行瀏覽重定向?
使用如下方式即可:response.sendRedirect("http://ybwen.home.chinaren.com/index.html");
也能物理地改變HTTP HEADER屬性,如下:
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn="/newpath/index.html";
response.setHeader("Location",newLocn);
%>
如何防止在JSP或SERVLET中的輸出不被BROWSER保存在CACHE中?
把如下腳本加入到JSP文件的開始即可:
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
在JSP中如何設置COOKIE?
COOKIE是作為HTTP HEADER的一部分被發送的,如下方法即可設置:
<%
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
%>
在JSP中如何刪除一個COOKIE?
<%
Cookie killMyCookie = new Cookie("mycookie", null);
killMyCookie.setMaxAge(0);
killMyCookie.setPath("/");
response.addCookie(killMyCookie);
%>
在一個JSP的請求處理中如何停止JSP的執行
如下例:
<%
if (request.getParameter("wen") != null) {
// do something
} else {
return;
}
%>
在JSP中如何定義方法
你可以定義方法,但是你不能直接訪問JSP的內置對象,而是通過參數的方法傳遞。如下:
<%!
public String howBadFrom(HttpServletRequest req) {
HttpSession ses = req.getSession();
...
return req.getRemoteHost();
}
%>
<%
out.print("in general,lao lee is not baddie ");
%>
<%= howBadFrom(request) %>
如果BROWSER已關閉了COOKIES,在JSP中我如何打開SESSION來跟蹤
使用URL重寫即可,如下:
hello1.jsp
<%@ page session="true" %>
<%
Integer num = new Integer(100);
session.putValue("num",num);
String url =response.encodeURL("hello2.jsp");
%>
<a href='<%=url%>'>hello2.jsp</a>
hello2.jsp
<%@ page session="true" %>
<%
Integer i= (Integer )session.getValue("num");
out.println("Num value in session is "+i.intValue());
%>
在JSP中能發送EMAIL嗎
可以使用SUN的專用包:sun.net.smtp包。如下腳本使用SmtpClient類發送EMAIL。
<%@ page import="sun.net.smtp.SmtpClient, java.io.*" %>
<%
String from="ybwen@sina.com";
String to="hewenjun@yeah.net, lei@who.com.cn";
try{
SmtpClient client = new SmtpClient("mail.xxxxx.xxx");
client.from(from);
client.to(to);
PrintStream message = client.startMessage();
message.println("To: " + to);
message.println("Subject: Sending email from JSP!");
message.println("This was sent from a JSP page!");
message.println();
message.println("Cool! ");
message.println();
message.println("Good Boy");
message.println("I'm in genius.com");
message.println();
client.closeServer();
}
catch (IOException e){
System.out.println("ERROR SENDING EMAIL:"+e);
}
%>
在SERVLET中我能調用一個JSP錯誤頁嗎
當然沒問題,如下展示了如何在一個SERVLET控制邏輯單元內調用一個JSP錯誤頁面。
protected void sendErrorRedirect(HttpServletRequest request,
HttpServletResponse response, String errorPageURL,
Throwable e)
throws ServletException, IOException {
request.setAttribute ("javax.servlet.jsp.jspException", e);
getServletConfig().getServletContext().
getRequestDispatcher(errorPageURL).forward(request,
response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) {
try {
// do something
} catch (Exception ex) {
try {
sendErrorRedirect(request,response,"/jsp/MyErrorPage.jsp",ex);
} catch (Exception e) {
e.printStackTrace();
}
}
}
JSP和APPLET如何通訊
JSP如何與EJB SessionBean通訊
下面的代碼段作了很好的示范
<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject,
foo.AccountHome, foo.Account" %>
<%!
//定義一個對SessionBeanHome接口實例的全局引用
AccountHome accHome=null;
public void jspInit() {
//獲得Home接口實例
InitialContext cntxt = new InitialContext( );
Object ref= cntxt.lookup("java:comp/env/ejb/AccountEJB");
accHome = (AccountHome)PortableRemoteObject.narrow(ref,AccountHome.class);
}
%>
<%
//實例化SessionBean
Account acct = accHome.create();
//調用遠程方法
acct.doWhatever(...);
// 如此等等
%>
當我使用一個結果集時,如何防止字段為"null"的字域顯示在我的HTML輸入文本域中?
可以定義一個簡單的函數來達到目的,如下:
<%!
String blanknull(String s) {
return (s == null) ? "" : s;
}
%>
然后在JSP的FORM中,可以這樣使用
<input type="text" name="shoesize" value="<%=blanknull(shoesize)%>">
如何中SERVLET或JSP下載一個文件(如:binary,text,executable)?
現提供兩個解決方案:
A:使用HTTP,如
點擊下載網絡恐龍圖片(這個地址是假的)
B:在Servlet中,通過設置ContentType和使用java.io包的Stream等類可作到.例如:
response.setContentType("application/x-msword");
然后想輸出緩沖中寫一些東東即可。
使用useBean標志初始化BEAN時如何接受初始化參數
使用如下兩標簽即可:
<jsp:getProperty name="wenBean" property="someProperty"/>
<jsp:setProperty name="wenBean" property="someProperty" value="someValue"/>
偉送頁?to.jsp
<%@ page contentType="text/html; charset=big5" %>
<a href="from.jsp?word=<%=java.net.URLEncoder.encode("二廠成型","big5")%>">傳送字符</a>
接收頁 from.jsp
<%@ page contentType="text/html; charset=big5" %>
<%
request.setCharacterEncoding("big5");
if(request.getParameter("word") != null){
????????String bb = request.getParameter("word");
????????out.print(bb);
}????????
%>
摘要: 我喜歡解決算法問題 哈哈為了解決這個問題 我寫了一個樹狀數據結構根節點為世界(我想這個根夠大了吧)下面有兩個子節點 分別為亞洲 歐洲亞洲的下面還有幾個節點分別是中國 韓國......中國下面的幾個節點分別是 福建省 湖北省......以次類推就是一個樹啦 (不知道這個樹是不是樓主需要的 反正沒事寫著玩唄 起碼能對樓主有所啟發吧)下面是代碼首先是 Type (一個對象是一條記錄)package?be...
閱讀全文
1. oncontextmenu="window.event.returnValue=false" 將徹底屏蔽鼠標右鍵
<table border oncontextmenu=return(false)><td>no</table> 可用于Table
2. <body onselectstart="return false"> 取消選取、防止復制
3. onpaste="return false" 不準粘貼
4. oncopy="return false;" oncut="return false;" 防止復制
5. <link rel="Shortcut Icon" href="favicon.ico"> IE地址欄前換成自己的圖標
6. <link rel="Bookmark" href="favicon.ico"> 可以在收藏夾中顯示出你的圖標
7. <input style="ime-mode:disabled"> 關閉輸入法
8. 永遠都會帶著框架
<script language="JavaScript"><!--
if (window == top)top.location.href = "frames.htm"; //frames.htm為框架網頁
// --></script>
9. 防止被人frame
<SCRIPT LANGUAGE=JAVASCRIPT><!--
if (top.location != self.location)top.location=self.location;
// --></SCRIPT>
10. 網頁將不能被另存為
<noscript><iframe src=*.html></iframe></noscript>
11. <input type=button value=查看網頁源代碼
onclick="window.location = "view-source:"+ "http://www.pconline.com.cn"">
12.刪除時確認
<a href="javascript:if(confirm("確實要刪除嗎?"))location="boos.asp?&areyou=刪除&page=1"">刪除</a>
13. 取得控件的絕對位置
//Javascript
<script language="Javascript">
function getIE(e){
var t=e.offsetTop;
var l=e.offsetLeft;
while(e=e.offsetParent){
t+=e.offsetTop;
l+=e.offsetLeft;
}
alert("top="+t+"/nleft="+l);
}
</script>
//VBScript
<script language="VBScript"><!--
function getIE()
dim t,l,a,b
set a=document.all.img1
t=document.all.img1.offsetTop
l=document.all.img1.offsetLeft
while a.tagName<>"BODY"
set a = a.offsetParent
t=t+a.offsetTop
l=l+a.offsetLeft
wend
msgbox "top="&t&chr(13)&"left="&l,64,"得到控件的位置"
end function
--></script>
14. 光標是停在文本框文字的最后
<script language="javascript">
function cc()
{
var e = event.srcElement;
var r =e.createTextRange();
r.moveStart("character",e.value.length);
r.collapse(true);
r.select();
}
</script>
<input type=text name=text1 value="123" onfocus="cc()">
15. 判斷上一頁的來源
javascript:
document.referrer
16. 最小化、最大化、關閉窗口
<object id=hh1 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Minimize"></object>
<object id=hh2 classid="clsid:ADB880A6-D8FF-11CF-9377-00AA003B7A11">
<param name="Command" value="Maximize"></object>
<OBJECT id=hh3 classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">
<PARAM NAME="Command" VALUE="Close"></OBJECT>
<input type=button value=最小化 onclick=hh1.Click()>
<input type=button value=最大化 onclick=hh2.Click()>
<input type=button value=關閉 onclick=hh3.Click()>
本例適用于IE
17.屏蔽功能鍵Shift,Alt,Ctrl
<script>
function look(){
if(event.shiftKey)
alert("禁止按Shift鍵!"); //可以換成ALT CTRL
}
document.onkeydown=look;
</script>
18. 網頁不會被緩存
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">
或者<META HTTP-EQUIV="expires" CONTENT="0">
19.怎樣讓表單沒有凹凸感?
<input type=text style="border:1 solid #000000">
或
<input type=text style="border-left:none; border-right:none; border-top:none; border-bottom:
1 solid #000000"></textarea>
20.<div><span>&<layer>的區別?
<div>(division)用來定義大段的頁面元素,會產生轉行
<span>用來定義同一行內的元素,跟<div>的唯一區別是不產生轉行
<layer>是ns的標記,ie不支持,相當于<div>
21.讓彈出窗口總是在最上面:
<body onblur="this.focus();">
22.不要滾動條?
讓豎條沒有:
<body style="overflow:scroll;overflow-y:hidden">
</body>
讓橫條沒有:
<body style="overflow:scroll;overflow-x:hidden">
</body>
兩個都去掉?更簡單了
<body scroll="no">
</body>
23.怎樣去掉圖片鏈接點擊后,圖片周圍的虛線?
<a href="#" onFocus="this.blur()"><img src="logo.jpg" border=0></a>
24.電子郵件處理提交表單
<form name="form1" method="post" action="mailto:****@***.com" enctype="text/plain">
<input type=submit>
</form>
25.在打開的子窗口刷新父窗口的代碼里如何寫?
window.opener.location.reload()
26.如何設定打開頁面的大小
<body onload="top.resizeTo(300,200);">
打開頁面的位置<body onload="top.moveBy(300,200);">
27.在頁面中如何加入不是滿鋪的背景圖片,拉動頁面時背景圖不動
<STYLE>
body
{background-image:url(logo.gif); background-repeat:no-repeat;
background-position:center;background-attachment: fixed}
</STYLE>
28. 檢查一段字符串是否全由數字組成
<script language="Javascript"><!--
function checkNum(str){return str.match(//D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
29. 獲得一個窗口的大小
document.body.clientWidth; document.body.clientHeight
30. 怎么判斷是否是字符
if (/[^/x00-/xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");
31.TEXTAREA自適應文字行數的多少
<textarea rows=1 name=s1 cols=27 onpropertychange="this.style.posHeight=this.scrollHeight">
</textarea>
32. 日期減去天數等于第二個日期
<script language=Javascript>
function cc(dd,dadd)
{
//可以加上錯誤處理
var a = new Date(dd)
a = a.valueOf()
a = a - dadd * 24 * 60 * 60 * 1000
a = new Date(a)
alert(a.getFullYear() + "年" + (a.getMonth() + 1) + "月" + a.getDate() + "日")
}
cc("12/23/2002",2)
</script>
33. 選擇了哪一個Radio
<HTML><script language="vbscript">
function checkme()
for each ob in radio1
if ob.checked then window.alert ob.value
next
end function
</script><BODY>
<INPUT name="radio1" type="radio" value="style" checked>Style
<INPUT name="radio1" type="radio" value="barcode">Barcode
<INPUT type="button" value="check" onclick="checkme()">
</BODY></HTML>
34.腳本永不出錯
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide
function killErrors() {
return true;
}
window.onerror = killErrors;
// -->
</SCRIPT>
35.ENTER鍵可以讓光標移到下一個輸入框
<input onkeydown="if(event.keyCode==13)event.keyCode=9">
36. 檢測某個網站的鏈接速度:
把如下代碼加入<body>區域中:
<script language=Javascript>
tim=1
setInterval("tim++",100)
b=1
var autourl=new Array()
autourl[1]="www.njcatv.net"
autourl[2]="javacool.3322.net"
autourl[3]="www.sina.com.cn"
autourl[4]="www.nuaa.edu.cn"
autourl[5]="www.cctv.com"
function butt(){
document.write("<form name=autof>")
for(var i=1;i<autourl.length;i++)
document.write("<input type=text name=txt"+i+" size=10 value=測試中……> =》<input type=text
name=url"+i+" size=40> =》<input type=button value=GO
onclick=window.open(this.form.url"+i+".value)><br>")
document.write("<input type=submit value=刷新></form>")
}
butt()
function auto(url){
document.forms[0]["url"+b].value=url
if(tim>200)
{document.forms[0]["txt"+b].value="鏈接超時"}
else
{document.forms[0]["txt"+b].value="時間"+tim/10+"秒"}
b++
}
function run(){for(var i=1;i<autourl.length;i++)document.write("<img src=http://"+autourl+"/"+Math.random()+" width=1 height=1
onerror=auto("http://"+autourl+"")>")}
run()</script>
37. 各種樣式的光標
auto :標準光標
default :標準箭頭
hand :手形光標
wait :等待光標
text :I形光標
vertical-text :水平I形光標
no-drop :不可拖動光標
not-allowed :無效光標
help :?幫助光標
all-scroll :三角方向標
move :移動標
crosshair :十字標
e-resize
n-resize
nw-resize
w-resize
s-resize
se-resize
sw-resize
38.頁面進入和退出的特效
進入頁面<meta http-equiv="Page-Enter" content="revealTrans(duration=x, transition=y)">
推出頁面<meta http-equiv="Page-Exit" content="revealTrans(duration=x, transition=y)">
這個是頁面被載入和調出時的一些特效。duration表示特效的持續時間,以秒為單位。transition表示使用哪種特效,取值為1-23:
0 矩形縮小
1 矩形擴大
2 圓形縮小
3 圓形擴大
4 下到上刷新
5 上到下刷新
6 左到右刷新
7 右到左刷新
8 豎百葉窗
9 橫百葉窗
10 錯位橫百葉窗
11 錯位豎百葉窗
12 點擴散
13 左右到中間刷新
14 中間到左右刷新
15 中間到上下
16 上下到中間
17 右下到左上
18 右上到左下
19 左上到右下
20 左下到右上
21 橫條
22 豎條
23 以上22種隨機選擇一種
39.在規定時間內跳轉
<META http-equiv=V="REFRESH" content="5;URL=http://www.51js.com">
40.網頁是否被檢索
<meta name="ROBOTS" content="屬性值">
其中屬性值有以下一些:
屬性值為"all": 文件將被檢索,且頁上鏈接可被查詢;
屬性值為"none": 文件不被檢索,而且不查詢頁上的鏈接;
屬性值為"index": 文件將被檢索;
屬性值為"follow": 查詢頁上的鏈接;
屬性值為"noindex": 文件不檢索,但可被查詢鏈接;
屬性值為"nofollow": 文件不被檢索,但可查詢頁上的鏈接。
// 將日期2005-02-30轉為"200502"
Function YearMonth(DateArg)
? Dim lYear, lMonth
? If DateArg = Null Or CStr(DateArg) = "" Then
??? YearMonth = ""
? Else
??? lYear = Year(DateArg)
??? lMonth = Month(DateArg)
??? YearMonth = CStr(lYear) + Right("0" + CStr(lMonth), 2)
? End If
End Function
// 將數字2030轉為"20:30"
Function ConvertToTime(Arg)
? Dim lHour, lMinute
? lHour = CStr(Left(Arg, 2))
? lMinute = CStr(Right(Arg, 2))
? If lHour > "24" Or lHour < "0" Or lMinute > "60" Or lMinute < "0" Then
??? ConvertToTime = ""
? Else
??? ConvertToTime = IIf(lHour = Null Or lHour = "", "", lHour + ":" + lMinute)
? End If
End Function
// 計算兩個時間的差
Function TimeDiff(BeginArg, EndArg)
? Dim lHour, lMinute
? lMinute = DateDiff("n", BeginArg, EndArg)
? lHour = Int(lMinute / 60)
? lMinute = lMinute - lHour * 60
? TimeDiff = CStr(lHour + lMinute / 60)
End Function
?
摘要: <
description
>
?
<
display
>
?
<
icon
>
這三個元素提供了Web容器部署工具用描述應用的信息.
<
icon
>
...
閱讀全文