URLEncoder.encode("要編碼的字串","UTF-8")
相對的,有加密也有解密,通常Bowser會自己解
URLDecoder.decode("要解碼的字串","UTF-8")
URLEncoder.encode("要編碼的字串","UTF-8")
URLDecoder.decode("要解碼的字串","UTF-8")
public void dosend() {
try {
//設定所要用的Mail 伺服器和所使用的傳送協定
Properties props = new Properties();
props.put("mail.host", mailserver);
props.put("mail.transport.protocol", "smtp");
Session session = Session.getInstance(props,null);
session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
//設定傳送郵件的發信人
msg.setFrom(new InternetAddress(From));
//設定傳送郵件至收信人的信箱
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(To));
//設定信中的主題
msg.setSubject(Subject);
//設定送信的時間
msg.setSentDate(new Date());
//設定傳送信的MIME Type
msg.setText(messageText);
//送信
Transport.send(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
import java.util.Hashtable;
Hashtable<String, String>ht = new Hashtable<String, String>();
ht.put("ID","abcde");
String text = ht.get("ID");
text輸出的文字為abcde
import java.util.Vector;
Vector vc = new Vector();
vc.add(20); //0
vc.add(40); //1
vc.add(30); //2
vc.get(0);
import java.util.Collections;
Collections.sort(vc);
import java.lang.Math;
int rnum = (int)(Math.random()*42+1);
資料表
Parent{
column:id,name
PK:id
}
Child{
column:id,name,ref_parent_id
PK:id
FK:ref_parent_id
}
DAO資料模型
package eg;
public class Parent{
private Integer Id;
private String Name;
private Set Children;
/*
getter and setter 省略
*/
}
package eg;
public class Child{
private Integer Id;
private String Name;
private Parent RefParent;
/*
getter and setter 省略
*/
}
Parent.hbm.xml{
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eg">
<class name="Parent" table="Parent">
<id column="id" name="Id" type="integer">
<generator class="native">
</id>
<property column="name" length="50"
name="Name" type="string"/>
<set cascade="all" inverse="true" name="Children">
<key column="ref_parent_id"><!--重要:Children的FK而不是PK-->
<one-to-many class="Child">
</set>
</class>
</hibernate-mapping>
}
Child.hbm.xml{
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eg">
<class name="Child" table="Child">
<id column="id" name="Id" type="integer">
<generator class="native">
</id>
<property column="name" generated="never" length="50"
name="Name" type="string"/>
<many-to-one class="Parent" column="ref_parent_id" name="RefParent" null="true">
</class>
</hibernate-mapping>
}
//open session lazy=true
Query query = null;
Session hsession = null;
List<Parent> list=null;
int i=0;
query=hsession.createQuery("FROM Parent");//
query.setFirstResult(0);
query.setMaxResults(5);//取5筆
list=query.list();
for(i=0;i<list.size();i++){
out.println("Parent 有 "+list.get(i).getChildren().size()+"個Child");
}
//close session
//取得指定Parent,關閉session,再取得Parent的Children
//open session lazy=true 延遲讀取
Query query = null;
Session hsession = null;
List<Parent> list=null;
int i=0,n=1;
query=hsession.createQuery("FROM Parent p WHERE p.Id=:id");
query.setInteger("id",n);
Parent p =(Parent)query.uniqueResult();
Hibernate.initialize(p.getChildren());
//close session
out.println("Parent 有 "+p.getChildren().size()+"個Child");
String display = " abc ";
System.out.println(display.trim());
資料表
ObjA{
column:id,name
PK:id
}
ObjB{
column:ref_obja_id,name
PK:ref_obja_id
FK:ref_obja_id
}
DAO資料模型
package eg;
public class ObjA{
private Integer Id;
private String Name;
private ObjB ObjB;
/*
getter and setter 省略
*/
}
package eg;
public class ObjB{
private Integer RefObjAId;
private String Name;
private ObjA RefObjA;
/*
getter and setter 省略
*/
}
ObjA.hbm.xml{
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eg">
<class name="ObjA" table="ObjA">
<id column="id" name="Id" type="integer">
<generator class="native">
</id>
<property column="name" length="50"
name="Name" type="string"/>
<one-to-one name="ObjB"
class="ObjB"
cascade="all"
/>
</class>
</hibernate-mapping>
}
ObjB.hbm.xml{
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="eg">
<class name="ObjB" table="ObjB">
<id column="ref_obja_id" name="RefObjAId" type="integer">
<generator class="foreign">
<param name="property">RefObjA</param>
</generator>
</id>
<property column="name" generated="never" length="50"
name="Name" type="string"/>
<one-to-one name="RefObjA"
class="ObjA"
constrained="true"
/>
</class>
</hibernate-mapping>
}
import java.lang.StringBuffer
StringBuffer xml = new StringBuffer();
xml.append("要輸出的字串");
xml.toString();
String display = "a&b&c";
String[] arrayS = display.split("&");
CODE{
display: block; /* fixes a strange ie margin bug */
font-family: Courier New;
font-size: 8pt;
overflow:auto;
background: #f0f0f0 url(http://klcintw.images.googlepages.com/Code_BG.gif) left top repeat-y;
border: 1px solid #ccc;
padding: 10px 10px 10px 21px;
max-height:200px;
height:200px; // for IE6
line-height: 1.2em;
}
import java.text.SimpleDateFormat;
SimpleDateFormat df =
new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String display = df.format(System.currentTimeMillis());
System.out.println(display);
df.parse(String source)可回傳Date()型態
Date d = df.parse("2010-01-01");
public class Account {
private String apid;
private String id;
private String pw;
get和set,用eclipse可以自動產生 如下
public String getApid() {
return apid;
}
public void setApid(String apid) {
this.apid = apid;
}
}
chkform=function(){
var PhoneNumber=document.getElementById('PhoneNum');
if(PhoneNum.value==''){
alert('請輸入帳號');
PhoneNum.focus();
return false;
}
}
表單範例
<form id="form1" name="form1" method="post" action="xxx.jsp" onsubmit="javascript:return(chkform());>
<input name="PhoneNum" id="PhoneNum" type="text">
<input type="submit" name="Submit" value="確認" />