最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery struts 驗(yàn)證唯一標(biāo)識(shí)(公用方法)

 更新時(shí)間:2013年03月27日 16:40:02   作者:  
本教程將為大家詳細(xì)介紹下使用公用方法驗(yàn)證jquery struts唯一標(biāo)識(shí),感興趣的朋友可以參考下哈,希望可以幫助到你
步驟一 引入js文件
復(fù)制代碼 代碼如下:

<script language="javascript1.2" src="<s:url value="/js/jquery.js" includeParams="false"/>"></script>
<script language="javascript1.2" src="<s:url value="/js/dictionary.js" includeParams="false"/>"></script>

步驟二 公用js文件 dictionary.js
復(fù)制代碼 代碼如下:

/**
*↓↓↓↓↓↓↓↓↓↓
*作者:ZhuangZi
*類名:公用方法初始化
*功能:公用方法初始化
*詳細(xì):公用方法初始化
*版本:1.0
*日期:2013-03-22
*說明:
*↑↑↑↑↑↑↑↑↑↑
*/
$(function(){
/*1.失去焦點(diǎn)驗(yàn)證↓↓↓*/
$("#code").blur(callback);//1.code就是你要驗(yàn)證的唯一標(biāo)志的控件ID 2.你控件后面必須要有個(gè)接收錯(cuò)誤信息的控件
/*2.提交時(shí)候驗(yàn)證↓↓↓*/
$("#submit").click(callback);//你頁面的提交按鈕ID
});
/**
*↓↓↓↓↓↓↓↓↓↓
*作者:ZhuangZi
*類名:驗(yàn)證唯一標(biāo)識(shí)公用方法
*功能:唯一驗(yàn)證
*詳細(xì):唯一標(biāo)識(shí)ID和提交按鈕ID要和下面保持一致
*版本:1.0
*日期:2013-03-22
*說明:
*↑↑↑↑↑↑↑↑↑↑
*/
function callback() {
var slef=$("#code");
var code=slef.val();
var submit=$("#submit");
var flag=$("#flag").val();
if(null==code||""==code){
slef.next().html("下載包標(biāo)識(shí)不能為空!");
submit.attr("disabled",true);
return;
}else{
if(!code.match("^\\w+$")){
slef.next().html("標(biāo)識(shí)由數(shù)字母或下劃線組成!");
return ;
}
slef.next().html("*");
}
$.ajax({
type:'post',
url:'../dictionary/checkCodeOnly.do',
data:'bean.code='+code+'&bean.flag='+flag,
dataType:'json',
success:function(json){
if(json>0){
slef.next().html("此標(biāo)識(shí)已存在!");
submit.attr("disabled",true);
return ;
}else{
slef.next().html("");
if(code != null && code!=""){
submit.attr("disabled",false);
}else{
submit.attr("disabled",true);
return;
}
}
},
error:function(){
alert('驗(yàn)證信息出錯(cuò)');
}
});
}

步驟三 頁面部分
復(fù)制代碼 代碼如下:

&nbsp;&nbsp; <s:hidden id="flag" value="3"/> <!-flag 什么類型的標(biāo)志->
<tr>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <td width="40%" height="33" class="addtabletd1">下載標(biāo)識(shí):</td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <td width="60%" height="33" class="addtabletd2"><div align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <s:textfield id="code" name="yhaoPortalsDownBean.downFlag" cssClass="textfrom" cssStyle="width:150px;"&nbsp; maxlength="200"/>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <font id="codeInfo" color="red">*</font>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div></td>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </tr>

步驟四 action里的方法
復(fù)制代碼 代碼如下:

/**
*
* @author ZhuangZi
* @class com.hzdracom.action.YhaoPortalsDictionaryAction
* @method checkCodeOnly
* @Directions 驗(yàn)證唯一標(biāo)識(shí)公用方法
* @date 2013-3-21上午10:09:04 void
*/
public void checkCodeOnly(){
String json="";
try{
json = String.valueOf(yhaoDictionaryService.checkCodeOnly(bean));
json=JSON.toJSONString(json);
System.out.println("json=="+json);
HttpServletResponse response=ServletActionContext.getResponse();
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
PrintWriter out;
out = response.getWriter();
out.println(json);
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
}

步驟五 dao里的方法
復(fù)制代碼 代碼如下:

<PRE class=java name="code"> public int checkCodeOnly(DictionaryBean bean)throws DataAccessException,Exception {
Object[] sqlParams = new Object[4];
int index = 0;
String sql="";
/* 驗(yàn)證頁面標(biāo)志是否唯一*/
if (bean.getFlag().equals("1")) {
sql = "select count(1) from YHAO_PORTALS_PAGE where PAGE_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
/* 驗(yàn)證類型志標(biāo)識(shí)是否唯一*/
if (bean.getFlag().equals("2")) {
sql = "select count(1) from YHAO_PORTALS_DOWNTYPE where DOWNTYPE_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
/* 驗(yàn)證下載志標(biāo)識(shí)是否唯一*/
if (bean.getFlag().equals("3")) {
sql = "select count(1) from YHAO_PORTALS_DOWN where DOWN_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
if (bean.getFlag().equals("4")) {
sql = "select count(1) from YHAO_PORTALS_KUAI where KUAI_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
Object[] sqlParamsEnd = new Object[index];
System.arraycopy(sqlParams, 0, sqlParamsEnd, 0, index);
int count = this.queryForInt(sql,sqlParamsEnd);
return count;
}</PRE>
<PRE></PRE>

相關(guān)文章

最新評論

蓝田县| 新巴尔虎左旗| 湾仔区| 城固县| 延长县| 阳新县| 东源县| 塘沽区| 浦城县| 济源市| 黎城县| 江山市| 临西县| 仪陇县| 景德镇市| 丰台区| 台湾省| 榕江县| 仪陇县| 南通市| 民勤县| 樟树市| 沁源县| 全州县| 保定市| 乐亭县| 贵港市| 冕宁县| 玉田县| 繁峙县| 西乌珠穆沁旗| 丹凤县| 南郑县| 离岛区| 宝清县| 辉县市| 永平县| 本溪| SHOW| 洞头县| 衡山县|