jquery struts一意識別の検証(共通メソッド)

4777 ワード

ステップ1 jsファイルの導入
 
  
">
">

ステップ2 jsファイルdictionary.js
 
  
/**
*↓↓↓↓↓↓↓↓↓↓
* :ZhuangZi
* :
* :
* :
* :1.0
* :2013-03-22
* :
*↑↑↑↑↑↑↑↑↑↑
*/
$(function(){
/*1. ↓↓↓*/
$("#code").blur(callback);//1.code ID 2.
/*2. ↓↓↓*/
$("#submit").click(callback);// ID
});
/**
*↓↓↓↓↓↓↓↓↓↓
* :ZhuangZi
* :
* :
* : 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(" !");
submit.attr("disabled",true);
return;
}else{
if(!code.match("^\\w+$")){
slef.next().html(" !");
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(" !");
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(' ');
}
});
}

ステップ3ページ
 
  
  

                   :
                  

                  
                  *
                  

                

ステップ actionの
 
  
/**
*
* @author ZhuangZi
* @class com.hzdracom.action.YhaoPortalsDictionaryAction
* @method checkCodeOnly
* @Directions
* @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();
}
}

5 daoの
 
  
 public int checkCodeOnly(DictionaryBean bean)throws DataAccessException,Exception { 
  
Object[] sqlParams = new Object[4];
int index = 0;
String sql="";
/* */
if (bean.getFlag().equals("1")) {
sql = "select count(1) from YHAO_PORTALS_PAGE where PAGE_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
/* */
if (bean.getFlag().equals("2")) {
sql = "select count(1) from YHAO_PORTALS_DOWNTYPE where DOWNTYPE_FLAG = ? ";
sqlParams[index]=bean.getCode();
index++;
}
/* */
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;
}