
2006年9月8日
1.下載所需軟件
1.1SVN服務(wù)端(svn-1.4.3-setup.exe)
http://subversion.tigris.org/project_packages.html
1.2把SVN設(shè)置成window服務(wù)(SVNService.exe)
我沒(méi)有下載地址,如有需要,留下你的email
1.3Eclipse的SVN插件(用Eclipse插件下載):
2.配置服務(wù)端
2.1安裝svn-1.4.3-setup.exe
2.2開(kāi)始->運(yùn)行->cmd->進(jìn)入SVN服務(wù)端的安裝目錄下面的bin目錄
2.3cmd下運(yùn)行svnadmin create SVN庫(kù)的位置(如:D:\SVN_PRJ)
2.4復(fù)制SVNService.exe到SVN服務(wù)端安裝目錄下的bin目錄
2.5cmd下運(yùn)行SVNService -install -d -r D:\SVN_PRJ(SVN庫(kù)的位置)
2.6如果想撤消掉后臺(tái)服務(wù),則運(yùn)行SVNService -remove
2.7進(jìn)入D:\SVN_PRJ\conf目錄下編輯svnserve.conf,內(nèi)容如下(切記下面幾行字前不能有空格):
[general]
anon-access = read #匿名訪問(wèn)權(quán)限,取值為read,write,none
auth-access = write #認(rèn)證用戶的權(quán)限
password-db = passwd #認(rèn)證用戶數(shù)據(jù)庫(kù),即允許連到SVN的用戶(當(dāng)前目錄下的passwd文件中存放的用戶及密碼)
realm = TESTING #在用戶認(rèn)證界面上出現(xiàn)的提示語(yǔ)句
2.8編輯D:\SVN_PRJ\conf\passwd文件,內(nèi)容如下
[users]
test = password #這時(shí)你連接SVN的時(shí)候可以使用用戶名為test密碼為password來(lái)連接SVN
2.9開(kāi)始->設(shè)置->控制面板->管理工具->服務(wù)->啟動(dòng)SVNService服務(wù)
3.Eclipse下配置SVN插件
3.1幫助->軟件更新->查找并安裝->搜索要安裝的新功能部件->新建遠(yuǎn)程站點(diǎn)->輸入一個(gè)任意的名稱->URL輸入
http://subclipse.tigris.org/update_1.2.x->確定->選中你剛才添加的遠(yuǎn)程站點(diǎn)->完成->選中Subclipse->執(zhí)行安裝操作
3.2窗口->打開(kāi)透視圖->SVN資源庫(kù)研究->右鍵->新建->資源庫(kù)位置->URL中輸入svn://127.0.0.1/->輸入2.7定義的用戶名test和密碼
password
4.提交工程
4.1右擊工程->小組->共享項(xiàng)目->選擇SVN->選擇svn://127.0.0.1(如果沒(méi)有,則創(chuàng)建一個(gè)新的資源庫(kù))->下一步->完成
5.下載工程
5.1在SVN資源庫(kù)透視圖下,點(diǎn)開(kāi)svn://127.0.0.1,會(huì)顯示出現(xiàn)在本機(jī)SVN上的所有工程,右擊你想下載的工程->檢出為->下一步->完成
6.基本操作
6.1同步
在MyEclipse J2EE透視圖下,右擊你要同步的工程->小組->與資源庫(kù)同步->這時(shí)會(huì)進(jìn)入同步透視圖,會(huì)顯示出本機(jī)與SVN上內(nèi)容有不同的文件,雙擊文件名,會(huì)顯示出兩個(gè)文件中哪里不同;
6.2提交
在同步透視圖下有"灰色向右的箭頭,表示你本機(jī)修改過(guò)",右擊該文件,可以選擇提交操作;
6.3覆蓋/更新
在同步透視圖下有"藍(lán)色向左的箭頭,表示你本機(jī)修改過(guò)",右擊該文件,可以選擇覆蓋/更新操作;
7.圖標(biāo)說(shuō)明
7.1灰色向右箭頭:本地修改過(guò)
7.2藍(lán)色向左箭頭:SVN上修改過(guò)
7.3灰色向右且中間有個(gè)加號(hào)的箭頭:本地比SVN上多出的文件
7.4藍(lán)色向左且中間有個(gè)加號(hào)的箭頭:SVN上比本地多出的文件
7.5灰色向右且中間有個(gè)減號(hào)的箭頭:本地刪除了,而SVN上未刪除的文件
7.6藍(lán)色向左且中間有個(gè)減號(hào)的箭頭:SVN上刪除了,而本地未刪除的文件
7.7紅色雙向箭頭:SVN上修改過(guò),本地也修改過(guò)的文件
8.一些我遇到的出錯(cuò)信息
8.1在上面講的3.2步輸入U(xiǎn)RL(svn://127.0.0.1)點(diǎn)下一步出現(xiàn)"svnserve.conf:
12: Option expected"錯(cuò)誤
你打開(kāi)svnserve.conf文件中的第
12行,該錯(cuò)誤是由于該行的前面有空格引起的,把左邊多出的空格刪除掉即可;
8.2在上面講的3.2步輸入U(xiǎn)RL(svn://127.0.0.1/SVN_PRJ)點(diǎn)下一步出現(xiàn)"svn://127.0.0.1/SVN_PRJ non-existent in revision '7'"錯(cuò)誤
URL錯(cuò)了,應(yīng)該輸入svn://127.0.0.1即可
9.SVN服務(wù)端自帶的基于命令行的操作語(yǔ)句
9.1設(shè)置SVN服務(wù)端安裝目錄下的/bin到環(huán)境變量中;
9.2在命令行下運(yùn)行svn import c:/test svn://127.0.0.1/test -m "initial import" --username test --password passwd可進(jìn)行上傳操作
9.3進(jìn)入你要檢出的目錄,在命令行下運(yùn)行svn checkout svn://127.0.0.1/test --username test -password passwd 可進(jìn)行檢出工程的操作
9.4在命令行下運(yùn)行svn commit test.txt -m "modified" --username test -password passwd 可進(jìn)行提交操作
9.5在命令行下運(yùn)行svn update -r HEAD test.txt --username test -password passwd 可進(jìn)行更新操作
注:上面講的127.0.0.1可以換成外網(wǎng)IP,或者局域網(wǎng)IP皆可(即,在家里創(chuàng)建一個(gè)SVN服務(wù)端,即可在公司去訪問(wèn)家里的SVN)
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class TempClass {
/**
* @param args
* @throws UnsupportedEncodingException
* @throws ClassNotFoundException
* @throws SQLException
*/
public static void main(String[] args) throws UnsupportedEncodingException {
String url = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=tran";
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection conn = DriverManager.getConnection(url, "sa", "sa");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select vcword from cn_other");
// mysql
String url_mysql = "jdbc:mysql://127.0.0.1:3306/zwspace";
Class.forName("org.gjt.mm.mysql.Driver");
Connection conn_mysql = DriverManager.getConnection(url_mysql,
"root", "root");
PreparedStatement st_mysql = conn_mysql
.prepareStatement("insert into chds_cihui(name) values(?)");
if (rs.next()) {
String rsname = rs.getString("vcword");
// String name = new String(rsname.getBytes("GB2312"),
// "GB2312");
// String name = new String(rsname.getBytes("UTF-8"), "GB2312");
// String name = new String(rsname.getBytes("utf8"), "GB2312");
// String name = new String(rsname.getBytes("iso-8859-1"),
// "GB2312");
// String name = new String(rsname.getBytes("GBK"), "GB2312");
// String name = new String(rsname.getBytes("GBK"), "GBK");
// String name = new String(rsname.getBytes("GB2312"), "GBK");
// String name = new String(rsname.getBytes("UTF-8"), "GBK");
// String name = new String(rsname.getBytes("iso-8859-1"),
// "GBK");
// String name = new String(rsname.getBytes("GBK"), "UTF-8");
// String name = new String(rsname.getBytes("GB2312"), "UTF-8");
// String name = new String(rsname.getBytes("UTF-8"), "UTF-8");
// String name = new String(rsname.getBytes("iso-8859-1"),
// "UTF-8");
// String name = new String(rsname.getBytes("GBK"),
// "iso-8859-1");
// String name = new String(rsname.getBytes("GB2312"),
// "iso-8859-1");
// String name = new String(rsname.getBytes("UTF-8"),
// "iso-8859-1");
// String name = new String(rsname.getBytes("iso-8859-1"),
// "iso-8859-1");
// String name = new String(rsname.getBytes(), "GBK");
// String name = new String(rsname.getBytes(), "GB2312");
// String name = new String(rsname.getBytes(), "UTF-8");
// String name = new String(rsname.getBytes(), "iso-8859-1");
String name = rsname;
System.out.println(rsname);
st_mysql.setString(1, name);
st_mysql.executeUpdate();
}
rs.close();
st.close();
conn.close();
st_mysql.close();
conn_mysql.close();
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
試過(guò)以上的所有編碼都無(wú)法解決數(shù)據(jù)在MYSQL中的亂碼問(wèn)題,看來(lái)是jdbc連mysql時(shí)的編碼不對(duì),于是
將 String url_mysql="jdbc:mysql://127.0.0.1:3306/zwspace";后加上編碼
String url_mysql="jdbc:mysql://127.0.0.1:3306/zwspace?useUnicode=true&characterEncoding=utf8";終于OK了
在使用hibernate項(xiàng)目中,持久化類的ID用Long與long有很大區(qū)別!!
用long 作為id,當(dāng)一個(gè)新的臨時(shí)類要持久化時(shí)會(huì)報(bào)一個(gè)這種錯(cuò):
Exception executing
batch: org.hibernate.StaleStateException:
Batch update returned unexpected row count from update: 0 actual
row count:
0 expected: 1
因?yàn)檫@個(gè)臨時(shí)類,已經(jīng)有一個(gè)id=0 (long的默認(rèn)值);這時(shí)hibernate 為錯(cuò)認(rèn)為這是一條持久化類,從而進(jìn)行更新操作,故報(bào)錯(cuò)!!
這時(shí)把持久類的id 類型改成Long 就OK了,再create 時(shí),臨時(shí)類的id為null ,hibernate 才會(huì)正確的判斷這是臨時(shí)類而進(jìn)行save操作!!
user.getUserinfo().setSex(new String(pu.getSex().getBytes("ISO8859_1"),"GB2312"));
user.setNickname(new String(pu.getName().getBytes("ISO8859_1"),"GB2312"));
userService.createUser(user); String(byte[] bytes, int offset, int length, String charsetName) 通過(guò)使用指定的字符集解碼指定的 byte 子數(shù)組,構(gòu)造一個(gè)新的
String
。
byte[] |
getBytes(String charsetName) 使用指定的字符集將此 String 編碼為 byte 序列,并將結(jié)果存儲(chǔ)到一個(gè)新的 byte 數(shù)組中 |
#800080
#7B7D62
#56B6E9
#4B8D32
<script language="JavaScript">
function doZoom(size){
document.getElementById("zwsky_content").style.fontSize=size+'px'
}
function ReImgSize(){
for (j=0;j<document.images.length;j++)
{
if (document.images[j].src.indexOf("
www.***.com/back") >0)
document.images[j].src=document.images[j].src.replace("
www.***.com/back","back.****.com/back");
}
}
</script>
............................
<body bottommargin="0" leftmargin="0" rightmargin="0" topmargin="0" onload="
ReImgSize()">
<input type="button" name="Submit3" value="搜 索" onClick="location.href='SearchResult.jsp?cluster_node_id=&key_word=' + document.CMS4JSearchForm.KEY_WORD.value + '&db_id=' + document.CMS4JSearchForm.DB_ID.value;">
這個(gè)錯(cuò)誤我一共遇到過(guò)兩次,一直沒(méi)有找到很好的解決方案,這個(gè)錯(cuò)誤產(chǎn)生原因相信大家都知道,因?yàn)樵趆ibernate中同一個(gè)session里面有了兩個(gè)相同標(biāo)識(shí)但是是不同實(shí)體.
一開(kāi)始按網(wǎng)上說(shuō)的用
session.merge(Object)報(bào)了一個(gè)錯(cuò),可能是沒(méi)有用好,改用 session.clear(); session.update(user);這樣就OK了,
方法為:
package org.springframework.orm.hibernate3.support;
...
public void modifyByMerge(User user) {
Session session = getHibernateTemplate().getSessionFactory().
getCurrentSession();
session.clear();
session.update(user);
}
...
項(xiàng)目用的是spring + hibernate所以得用getHibernateTemplate().getSessionFactory().getCurrentSession();得當(dāng)前Session
上一次在做交友模板時(shí),出來(lái)了這種問(wèn)題,后來(lái)才發(fā)現(xiàn)是hibernate的一個(gè)映射文件配錯(cuò)了,今天在做DC攝影時(shí),
映射文件加了一個(gè)lazy="false" fetch="join" 結(jié)果,也出現(xiàn)了數(shù)據(jù)重復(fù)取。
<many-to-one name="user" column="user_id" class="com.zwspace.domain.User" lazy="false" fetch="join" />
這樣也會(huì)有錯(cuò)嗎!想不通,只能把它給刪了。
js驗(yàn)證表單大全
1. 長(zhǎng)度限制
<script>
function test()
{
if(document.a.b.value.length>50)
{
alert("不能超過(guò)50個(gè)字符!");
document.a.b.focus();
return false;
}
}
</script>
<form name=a onsubmit="return test()">
<textarea name="b" cols="40" wrap="VIRTUAL" rows="6"></textarea>
<input type="submit" name="Submit" value="check">
</form>
2. 只能是漢字
<input onkeyup="value="/oblog/value.replace(/[^\u4E00-\u9FA5]/g,'')">
3." 只能是英文
<script language=javascript>
function onlyEng()
{
if(!(event.keyCode>=65&&event.keyCode<=90))
event.returnvalue=false;
}
</script>
<input onkeydown="onlyEng();">
4. 只能是數(shù)字
<script language=javascript>
function onlyNum()
{
if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105)))
//考慮小鍵盤上的數(shù)字鍵
event.returnvalue=false;
}
</script>
<input onkeydown="onlyNum();">
5. 只能是英文字符和數(shù)字
<input onkeyup="value="/oblog/value.replace(/[\W]/g,"'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))">
6. 驗(yàn)證油箱格式
<SCRIPT LANGUAGE=javascript RUNAT=Server>
function isEmail(strEmail) {
if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
return true;
else
alert("oh");
}
</SCRIPT>
<input type=text onblur=isEmail(this.value)>
7. 屏蔽關(guān)鍵字(這里屏蔽***和****)
<script language="javascript1.2">
function test() {
if((a.b.value.indexOf ("***") == 0)||(a.b.value.indexOf ("****") == 0)){
alert(":)");
a.b.focus();
return false;}
}
</script>
<form name=a onsubmit="return test()">
<input type=text name=b>
<input type="submit" name="Submit" value="check">
</form>
8. 兩次輸入密碼是否相同
<FORM METHOD=POST ACTION="">
<input type="password" id="input1">
<input type="password" id="input2">
<input type="button" value="test" onclick="check()">
</FORM>
<script>
function check()
{
with(document.all){
if(input1.value!=input2.value)
{
alert("false")
input1.value = "";
input2.value = "";
}
else document.forms[0].submit();
}
}
</script>
夠了吧 :)
屏蔽右鍵 很酷
oncontextmenu="return false" ondragstart="return false" onselectstart="return false"
加在body中
二
2.1 表單項(xiàng)不能為空
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.name.value.length == 0) {
alert("請(qǐng)輸入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
-->
</script>
2.2 比較兩個(gè)表單項(xiàng)的值是否相同
<script language="javascript">
<!--
function CheckForm()
if (document.form.PWD.value != document.form.PWD_Again.value) {
alert("您兩次輸入的密碼不一樣!請(qǐng)重新輸入.");
document.ADDUser.PWD.focus();
return false;
}
return true;
}
-->
</script>
2.3 表單項(xiàng)只能為數(shù)字和"_",用于電話/銀行帳號(hào)驗(yàn)證上,可擴(kuò)展到域名注冊(cè)等
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //可以自己增加可輸入值
var i;
var c;
if(String.charAt( 0 )=='-')
return false;
if( String.charAt( String.length - 1 ) == '-' )
return false;
for( i = 0; i < String.length; i ++ )
{
c = String.charAt( i );
if (Letters.indexOf( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber(document.form.TEL.value)) {
alert("您的電話號(hào)碼不合法!");
document.form.TEL.focus();
return false;
}
return true;
}
-->
</script>
2.4 表單項(xiàng)輸入數(shù)值/長(zhǎng)度限定
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.count.value > 100 || document.form.count.value < 1)
{
alert("輸入數(shù)值不能小于零大于100!");
document.form.count.focus();
return false;
}
if (document.form.MESSAGE.value.length<10)
{
alert("輸入文字小于10!");
document.form.MESSAGE.focus();
return false;
}
return true;
}
//-->
</script>
2.5 中文/英文/數(shù)字/郵件地址合法性判斷
<SCRIPT LANGUAGE="javascript">
<!--
function isEnglish(name) //英文值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return false;
}
return true;
}
function isChinese(name) //中文值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return true;
}
return false;
}
function isMail(name) // E-mail值檢測(cè)
{
if(! isEnglish(name))
return false;
i = name.indexOf(" at ");
j = name dot lastIndexOf(" at ");
if(i == -1)
return false;
if(i != j)
return false;
if(i == name dot length)
return false;
return true;
}
function isNumber(name) //數(shù)值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charAt(i) < "0" || name.charAt(i) > "9")
return false;
}
return true;
}
function CheckForm()
{
if(! isMail(form.Email.value)) {
alert("您的電子郵件不合法!");
form.Email.focus();
return false;
}
if(! isEnglish(form.name.value)) {
alert("英文名不合法!");
form.name.focus();
return false;
}
if(! isChinese(form.cnname.value)) {
alert("中文名不合法!");
form.cnname.focus();
return false;
}
if(! isNumber(form.PublicZipCode.value)) {
alert("郵政編碼不合法!");
form.PublicZipCode.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
2.6 限定表單項(xiàng)不能輸入的字符
<script language="javascript">
<!--
function contain(str,charset)// 字符串包含測(cè)試函數(shù)
{
var i;
for(i=0;i<charset.length;i++)
if(str.indexOf(charset.charAt(i))>=0)
return true;
return false;
}
function CheckForm()
{
if ((contain(document.form.NAME.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><")))
{
alert("輸入了非法字符");
document.form.NAME.focus();
return false;
}
return true;
}
//-->
</script>
1. 檢查一段字符串是否全由數(shù)字組成
---------------------------------------
<script language="Javascript"><!--
function checkNum(str){return str.match(/\D/)==null}
alert(checkNum("1232142141"))
alert(checkNum("123214214a1"))
// --></script>
2. 怎么判斷是否是字符
---------------------------------------
if (/[^\x00-\xff]/g.test(s)) alert("含有漢字");
else alert("全是字符");
3. 怎么判斷是否含有漢字
---------------------------------------
if (escape(str).indexOf("%u")!=-1) alert("含有漢字");
else alert("全是字符");
4. 郵箱格式驗(yàn)證
---------------------------------------
//函數(shù)名:chkemail
//功能介紹:檢查是否為Email Address
//參數(shù)說(shuō)明:要檢查的字符串
//返回值:0:不是 1:是
function chkemail(a)
{ var i=a.length;
var temp = a.indexOf('@');
var tempd = a.indexOf('.');
if (temp > 1) {
if ((i-temp) > 3){
if ((i-tempd)>0){
return 1;
}
}
}
return 0;
}
5. 數(shù)字格式驗(yàn)證
---------------------------------------
//函數(shù)名:fucCheckNUM
//功能介紹:檢查是否為數(shù)字
//參數(shù)說(shuō)明:要檢查的數(shù)字
//返回值:1為是數(shù)字,0為不是數(shù)字
function fucCheckNUM(NUM)
{
var i,j,strTemp;
strTemp="0123456789";
if ( NUM.length== 0)
return 0
for (i=0;i<NUM.length;i++)
{
j=strTemp.indexOf(NUM.charAt(i));
if (j==-1)
{
//說(shuō)明有字符不是數(shù)字
return 0;
}
}
//說(shuō)明是數(shù)字
return 1;
}
6. 電話號(hào)碼格式驗(yàn)證
---------------------------------------
//函數(shù)名:fucCheckTEL
//功能介紹:檢查是否為電話號(hào)碼
//參數(shù)說(shuō)明:要檢查的字符串
//返回值:1為是合法,0為不合法
function fucCheckTEL(TEL)
{
var i,j,strTemp;
strTemp="0123456789-()# ";
for (i=0;i<TEL.length;i++)
{
j=strTemp.indexOf(TEL.charAt(i));
if (j==-1)
{
//說(shuō)明有字符不合法
return 0;
}
}
//說(shuō)明合法
return 1;
}
7. 判斷輸入是否為中文的函數(shù)
---------------------------------------
function ischinese(s){
var ret=true;
for(var i=0;i<s.length;i++)
ret=ret && (s.charCodeAt(i)>=10000);
return ret;
}
8. 綜合的判斷用戶輸入的合法性的函數(shù)
---------------------------------------
<script language="javascript">
//限制輸入字符的位數(shù)開(kāi)始
//m是用戶輸入,n是要限制的位數(shù)
function issmall(m,n)
{
if ((m<n) && (m>0))
{
return(false);
}
else
{return(true);}
}
9. 判斷密碼是否輸入一致
---------------------------------------
function issame(str1,str2)
{
if (str1==str2)
{return(true);}
else
{return(false);}
}
10. 判斷用戶名是否為數(shù)字字母下滑線
---------------------------------------
function notchinese(str){
var reg=/[^A-Za-z0-9_]/g
if (reg.test(str)){
return (false);
}else{
return(true); }
}
11. form文本域的通用校驗(yàn)函數(shù)
---------------------------------------
作用:檢測(cè)所有必須非空的input文本,比如姓名,賬號(hào),郵件地址等等。
該校驗(yàn)現(xiàn)在只針對(duì)文本域,如果要針對(duì)form里面的其他域?qū)ο螅梢愿淖兣袛鄺l件。
使用方法:在要檢測(cè)的文本域中加入title文字。文字是在提示信息,你要提示給用戶的該字段的中文名。比如要檢測(cè)用戶名
html如下<input name="txt_1" title="姓名">,當(dāng)然,最好用可視化工具比如dreamweaver什么的來(lái)編輯域。
如果要檢測(cè)數(shù)字類型數(shù)據(jù)的話,再把域的id統(tǒng)一為sz.
javascript判斷日期類型比較麻煩,所以就沒(méi)有做日期類型校驗(yàn)的程序了.高手可以補(bǔ)充。
程序比較草,只是提供一個(gè)思路。拋磚引玉! :)
哦,對(duì)了,函數(shù)調(diào)用方法:< form onsubmit="return dovalidate()">
function dovalidate()
{
fm=document.forms[0] //只檢測(cè)一個(gè)form,如果是多個(gè)可以改變判斷條件
for(i=0;i<fm.length;i++)
{
//檢測(cè)判斷條件,根據(jù)類型不同可以修改
if(fm[i].tagName.toUpperCase()=="INPUT" &&fm[i].type.toUpperCase()=="TEXT" && (fm[i].title!=""))
if(fm[i].value="/blog/="")//
{
str_warn1=fm[i].title+"不能為空!";
alert(str_warn1);
fm[i].focus();
return false;
}
if(fm[i].id.toUpperCase()=="SZ")//數(shù)字校驗(yàn)
{
if(isNaN(fm[i].value))
{ str_warn2=fm[i].title+"格式不對(duì)";
alert(str_warn2);
fm[i].focus();
return false;
}
}
}
return true;
}
2 >表單提交驗(yàn)證類
2.1 表單項(xiàng)不能為空
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.name.value.length == 0) {
alert("請(qǐng)輸入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
-->
</script>
2.2 比較兩個(gè)表單項(xiàng)的值是否相同
<script language="javascript">
<!--
function CheckForm()
if (document.form.PWD.value != document.form.PWD_Again.value) {
alert("您兩次輸入的密碼不一樣!請(qǐng)重新輸入.");
document.ADDUser.PWD.focus();
return false;
}
return true;
}
-->
</script>
2.3 表單項(xiàng)只能為數(shù)字和"_",用于電話/銀行帳號(hào)驗(yàn)證上,可擴(kuò)展到域名注冊(cè)等
<script language="javascript">
<!--
function isNumber(String)
{
var Letters = "1234567890-"; //可以自己增加可輸入值
var i;
var c;
if(String.charAt( 0 )=='-')
return false;
if( String.charAt( String.length - 1 ) == '-' )
return false;
for( i = 0; i < String.length; i ++ )
{
c = String.charAt( i );
if (Letters.indexOf( c ) < 0)
return false;
}
return true;
}
function CheckForm()
{
if(! isNumber(document.form.TEL.value)) {
alert("您的電話號(hào)碼不合法!");
document.form.TEL.focus();
return false;
}
return true;
}
-->
</script>
2.4 表單項(xiàng)輸入數(shù)值/長(zhǎng)度限定
<script language="javascript">
<!--
function CheckForm()
{
if (document.form.count.value > 100 || document.form.count.value < 1)
{
alert("輸入數(shù)值不能小于零大于100!");
document.form.count.focus();
return false;
}
if (document.form.MESSAGE.value.length<10)
{
alert("輸入文字小于10!");
document.form.MESSAGE.focus();
return false;
}
return true;
}
//-->
</script>
2.5 中文/英文/數(shù)字/郵件地址合法性判斷
<SCRIPT LANGUAGE="javascript">
<!--
function isEnglish(name) //英文值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return false;
}
return true;
}
function isChinese(name) //中文值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charCodeAt(i) > 128)
return true;
}
return false;
}
function isMail(name) // E-mail值檢測(cè)
{
if(! isEnglish(name))
return false;
i = name.indexOf(" at ");
j = name dot lastIndexOf(" at ");
if(i == -1)
return false;
if(i != j)
return false;
if(i == name dot length)
return false;
return true;
}
function isNumber(name) //數(shù)值檢測(cè)
{
if(name.length == 0)
return false;
for(i = 0; i < name.length; i++) {
if(name.charAt(i) < "0" || name.charAt(i) > "9")
return false;
}
return true;
}
function CheckForm()
{
if(! isMail(form.Email.value)) {
alert("您的電子郵件不合法!");
form.Email.focus();
return false;
}
if(! isEnglish(form.name.value)) {
alert("英文名不合法!");
form.name.focus();
return false;
}
if(! isChinese(form.cnname.value)) {
alert("中文名不合法!");
form.cnname.focus();
return false;
}
if(! isNumber(form.PublicZipCode.value)) {
alert("郵政編碼不合法!");
form.PublicZipCode.focus();
return false;
}
return true;
}
//-->
</SCRIPT>
2.6 限定表單項(xiàng)不能輸入的字符
<script language="javascript">
<!--
function contain(str,charset)// 字符串包含測(cè)試函數(shù)
{
var i;
for(i=0;i<charset.length;i++)
if(str.indexOf(charset.charAt(i))>=0)
return true;
return false;
}
function CheckForm()
{
if ((contain(document.form.NAME.value, "%\(\)><")) || (contain(document.form.MESSAGE.value, "%\(\)><")))
{
alert("輸入了非法字符");
document.form.NAME.focus();
return false;
}
return true;
}
//-->
</script>
Java/J2EE中文問(wèn)題終極解決之道
Java中文問(wèn)題一直困擾著很多初學(xué)者,如果了解了Java系統(tǒng)的中文問(wèn)題原理,我們就可以對(duì)中文問(wèn)題能夠采取根本的解決之道。
最古老的解決方案是使用String的字節(jié)碼轉(zhuǎn)換,這種方案問(wèn)題是不方便,我們需要破壞對(duì)象封裝性,進(jìn)行字節(jié)碼轉(zhuǎn)換。
還有一種方式是對(duì)J2EE容器進(jìn)行編碼設(shè)置,如果J2EE應(yīng)用系統(tǒng)脫離該容器,則會(huì)發(fā)生亂碼,而且指定容器配置不符合J2EE應(yīng)用和容器分離的原則。
在Java內(nèi)部運(yùn)算中,涉及到的所有字符串都會(huì)被轉(zhuǎn)化為UTF-8編碼來(lái)進(jìn)行運(yùn)算。那么,在被Java轉(zhuǎn)化之前,字符串是什么樣的字符集? Java總是根據(jù)操作系統(tǒng)的默認(rèn)編碼字符集來(lái)決定字符串的初始編碼,而且Java系統(tǒng)的輸入和輸出的都是采取操作系統(tǒng)的默認(rèn)編碼。
因此,如果能統(tǒng)一Java系統(tǒng)的輸入、輸出和操作系統(tǒng)3者的編碼字符集合,將能夠使Java系統(tǒng)正確處理和顯示漢字。這是處理Java系統(tǒng)漢字的一個(gè)原則,但是在實(shí)際項(xiàng)目中,能夠正確抓住和控制住Java系統(tǒng)的輸入和輸出部分是比較難的。J2EE中,由于涉及到外部瀏覽器和數(shù)據(jù)庫(kù)等,所以中文問(wèn)題亂碼顯得非常突出。
J2EE應(yīng)用程序是運(yùn)行在J2EE容器中。在這個(gè)系統(tǒng)中,輸入途徑有很多種:一種是通過(guò)頁(yè)面表單打包成請(qǐng)求(request)發(fā)往服務(wù)器的;第二種是通過(guò)數(shù)據(jù)庫(kù)讀入;還有第3種輸入比較復(fù)雜,JSP在第一次運(yùn)行時(shí)總是被編譯成Servlet,JSP中常常包含中文字符,那么編譯使用javac時(shí),Java將根據(jù)默認(rèn)的操作系統(tǒng)編碼作為初始編碼。除非特別指定,如在Jbuilder/eclipse中可以指定默認(rèn)的字符集。
輸出途徑也有幾種:第一種是JSP頁(yè)面的輸出。由于JSP頁(yè)面已經(jīng)被編譯成Servlet,那么在輸出時(shí),也將根據(jù)操作系統(tǒng)的默認(rèn)編碼來(lái)選擇輸出編碼,除非指定輸出編碼方式;還有輸出途徑是數(shù)據(jù)庫(kù),將字符串輸出到數(shù)據(jù)庫(kù)。
由此看來(lái),一個(gè)J2EE系統(tǒng)的輸入輸出是非常復(fù)雜,而且是動(dòng)態(tài)變化的,而Java是跨平臺(tái)運(yùn)行的,在實(shí)際編譯和運(yùn)行中,都可能涉及到不同的操作系統(tǒng),如果任由Java自由根據(jù)操作系統(tǒng)來(lái)決定輸入輸出的編碼字符集,這將不可控制地出現(xiàn)亂碼。
正是由于Java的跨平臺(tái)特性,使得字符集問(wèn)題必須由具體系統(tǒng)來(lái)統(tǒng)一解決,所以在一個(gè)Java應(yīng)用系統(tǒng)中,解決中文亂碼的根本辦法是明確指定整個(gè)應(yīng)用系統(tǒng)統(tǒng)一字符集。
指定統(tǒng)一字符集時(shí),到底是指定ISO8859_1 、GBK還是UTF-8呢?
(1)如統(tǒng)一指定為ISO8859_1,因?yàn)槟壳按蠖鄶?shù)軟件都是西方人編制的,他們默認(rèn)的字符集就是ISO8859_1,包括操作系統(tǒng)Linux和數(shù)據(jù)庫(kù)MySQL等。這樣,如果指定Jive統(tǒng)一編碼為ISO8859_1,那么就有下面3個(gè)環(huán)節(jié)必須把握:
開(kāi)發(fā)和編譯代碼時(shí)指定字符集為ISO8859_1。
運(yùn)行操作系統(tǒng)的默認(rèn)編碼必須是ISO8859_1,如Linux。
在JSP頭部聲明:<%@ page contentType="text/html;charset=ISO8859_1" %>。
(2)如果統(tǒng)一指定為GBK中文字符集,上述3個(gè)環(huán)節(jié)同樣需要做到,不同的是只能運(yùn)行在默認(rèn)編碼為GBK的操作系統(tǒng),如中文Windows。
統(tǒng)一編碼為ISO8859_1和GBK雖然帶來(lái)編制代碼的方便,但是各自只能在相應(yīng)的操作系統(tǒng)上運(yùn)行。但是也破壞了Java跨平臺(tái)運(yùn)行的優(yōu)越性,只在一定范圍內(nèi)行得通。例如,為了使得GBK編碼在linux上運(yùn)行,設(shè)置Linux編碼為GBK。
那么有沒(méi)有一種除了應(yīng)用系統(tǒng)以外不需要進(jìn)行任何附加設(shè)置的中文編碼根本解決方案呢?
將Java/J2EE系統(tǒng)的統(tǒng)一編碼定義為UTF-8。UTF-8編碼是一種兼容所有語(yǔ)言的編碼方式,惟一比較麻煩的就是要找到應(yīng)用系統(tǒng)的所有出入口,然后使用UTF-8去“結(jié)扎”它。
一個(gè)J2EE應(yīng)用系統(tǒng)需要做下列幾步工作:
- 開(kāi)發(fā)和編譯代碼時(shí)指定字符集為UTF-8。JBuilder和Eclipse都可以在項(xiàng)目屬性中設(shè)置。
- 使用過(guò)濾器,如果所有請(qǐng)求都經(jīng)過(guò)一個(gè)Servlet控制分配器,那么使用Servlet的filter執(zhí)行語(yǔ)句,將所有來(lái)自瀏覽器的請(qǐng)求(request)轉(zhuǎn)換為UTF-8,因?yàn)闉g覽器發(fā)過(guò)來(lái)的請(qǐng)求包根據(jù)瀏覽器所在的操作系統(tǒng)編碼,可能是各種形式編碼。關(guān)鍵一句:
request.setCharacterEncoding("UTF-8")。 網(wǎng)上有此filter的源碼,Jdon框架源碼中com.jdon.util.SetCharacterEncodingFilter 需要配置web.xml 激活該Filter。
- 在JSP頭部聲明:<%@ page contentType="text/html;charset= UTF-8" %>。
- 在Jsp的html代碼中,聲明UTF-8:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- 設(shè)定數(shù)據(jù)庫(kù)連接方式是UTF-8。例如連接MYSQL時(shí)配置URL如下:
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8 注意,上述寫(xiě)法是JBoss的mysql-ds.xml寫(xiě)法,多虧網(wǎng)友提示,在tomcat中&要寫(xiě)成&即可。一般其他數(shù)據(jù)庫(kù)都可以通過(guò)管理設(shè)置設(shè)定UTF-8
- 其他和外界交互時(shí)能夠設(shè)定編碼時(shí)就設(shè)定UTF-8,例如讀取文件,操作XML等。
筆者以前在Jsp/Servlet時(shí)就采取這個(gè)原則,后來(lái)使用Struts、Tapestry、EJB、Hibernate、Jdon等框架時(shí),從未被亂碼困擾過(guò),可以說(shuō)適合各種架構(gòu)。希望本方案供更多初學(xué)者分享,減少Java/J2EE的第一個(gè)攔路虎,也避免因?yàn)椴扇∫恍┡R時(shí)解決方案,導(dǎo)致中文問(wèn)題一直出現(xiàn)在新的技術(shù)架構(gòu)中。
|
<entry key="webaddsuccess" value="redirect:/web.do?method=friendSitelist"/>
jsp頁(yè)面代碼:
<% boolean isClubManager=false;
Long regionid2 = ((Region)request.getSession().getAttribute("RegionSession")).getId();
isClubManager=newsPostService.isClubManager(regionid2);
Region region=(Region)request.getSession().getAttribute("RegionSession");
String memo=region.getParent().getMemo();
request.setAttribute("memo",memo);
%>
.........
<gd:label maxLength="150" text="${memo}"/>
ClientService.java
package com.soft.client;
import org.apache.axis.client.Service;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
import org.apache.axis.client.Call;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import javax.xml.namespace.QName;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import java.rmi.RemoteException;
public class ClientService {
public ClientService() {
}
public UserDTO getUserDTO() {
String endpoint = "http://localhost:8080/WebModule/services/Myservice";
QName qset = new QName("urn:Myservice", "UserDTO");
QName qmethod = new QName("urn:Myservice", "getUserDTO");
Class clsUserDTO = UserDTO.class;
UserDTO dto = new UserDTO();
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.registerTypeMapping(clsUserDTO, qset,
new BeanSerializerFactory(clsUserDTO, qset),
new BeanDeserializerFactory(clsUserDTO,qset));
call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(qmethod);
call.setReturnClass(clsUserDTO);
dto = (UserDTO) call.invoke(new Object[] {});
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dto;
}
public static void main(String[] args) {
ClientService cs = new ClientService();
UserDTO user = cs.getUserDTO();
System.out.println(user.getPassword());
System.out.println(user.getUsername());
}
}
UserDTO.java
package com.soft.client;
public class UserDTO {
private String username;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
報(bào)錯(cuò)信息:
org.apache.jasper.JasperException: <h3>Validation error messages from TagLibraryValidator for c</h3><p>null: com.caucho.xml.XmlParseException: stream:276: expected character in cdata at `?' (\ufffd)</p><h3>Validation error messages from TagLibraryValidator for sql</h3><p>null: com.caucho.xml.XmlParseException: stream:276: expected character in cdata at `?' (\ufffd)</p><h3>Validation error messages from TagLibraryValidator for x</h3><p>null: com.caucho.xml.XmlParseException: stream:276: expected character in cdata at `?' (\ufffd)</p><h3>Validation error messages from TagLibraryValidator for fmt</h3><p>null: com.caucho.xml.XmlParseException: stream:276: expected character in cdata at `?' (\ufffd)</p>
<script language="javascript">document.write(week[${status.index}])</script>
.jsp加入代碼:
<c:set scope="session" value="${page.result}" var="page"></c:set>
<c:set value="${page1.result}" var="page1" scope="session"></c:set>
<c:set value="${page2.result}" var="page2" scope="session"></c:set>
報(bào)錯(cuò):
avax.servlet.jsp.el.ELException: The "." operator was supplied with an index value of type "java.lang.String" to be applied to a List or array, but that value cannot be converted to an integer.
可見(jiàn)這種<c:set>的用法是錯(cuò)誤的!!!!!!
import java.util.Map.Entry;
private static Map oldvote=new HashMap();
...............................
ModelAndView mav = new ModelAndView();
String voteid = ServletRequestUtils.getRequiredStringParameter(request,
"voteid");
String ip = ServletRequestUtils.getStringParameter(request, "ip");
//遍歷HasMap
Boolean isoldvote=false;
Iterator it=oldvote.entrySet().iterator();
while(it.hasNext()){
Entry entry=(Entry) it.next();
Object key=entry.getKey();
Object value=entry.getValue();
if(key.equals(voteid)&&value.equals(ip)){
isoldvote=true;
break;
}
}
if (isoldvote) {
...............................
<a href="javascript:history.go(-1);">[返回]</javascript>
1.
<html>
?<head>
??<title>transPara.htm</title>
?</head>
<body>
?<form method="POST" action="acceptPara.jsp">
? ??<p align="center">
??姓 名:<input type="text" name="name" size="20"><br>
? ??年 齡: <input type="text" name="age" size="15"><br>
? ??性 別:
???<input type="radio" value="male" checked name="sex">
????男 ?
? ???<input type="radio" name="sex" value="female">女</p>
? ??<p align="center">
???<input type="submit" value="submit" name="submit">
? ???<input type="reset" value="reset" name="reset"></p>
?</form>
</body>
</html>
2.
<html>
<%@ page contentType="text/html;charset=gb2312"%>
<jsp:useBean id="atest"? class="test.AcceptPara"/>
<head><title>acceptPara.jsp</title></head>
<body>
<jsp:setProperty name="atest" property="*"/>?? //? ***將javabean中的屬性自動(dòng)與html提交過(guò)來(lái)的變量匹配***********
Value of property "name" :
<jsp:getProperty name="atest" property="name"/><br>
Value of property "age" :
<jsp:getProperty name="atest" property="age"/><br>
Value of property "sex" :
<jsp:getProperty name="atest" property="sex"/><br>
Value of property "submit" :
<jsp:getProperty name="atest" property="submit"/><br>
</body>
</html>
3.
package test;//?? 在一些tomcat舊版本包定義一定要有,且在jsp引用中如下:<jsp:useBean id="atest"? class="test.AcceptPara"/>? 編譯后放在\WEB-INF\classes\test\中
public class AcceptPara{
?String name;
?int age;
?String sex;
?String submit;
?
?public void setName(String value){
??name=value;
?}
?
?public String getName(){
??return name;
?}
?
?public void setAge(int value){
??age=value;
?}
?
?public int getAge(){
??return age;
?}
?
?public void setSex(String value){
??sex=value;
?}
?
?public String getSex(){
??return sex;
?}
?
?public void setSubmit(String value){
??submit=value;
?}
?
?public String getSubmit(){
??return submit;
?}
??
?public void acceptPara(){}
?
}