Jquerystruts unique authentication (public method) _ jquery-js tutorial

Source: Internet
Author: User
This tutorial describes how to use a common method to verify the unique ID of jquerystruts. If you are interested, refer to the following link and hope to help you. Step 1 introduce the js File

The Code is as follows:


"> Script
"> Script


Step 2. Public the js file dictionary. js

The Code is as follows:


/**
* When there are too many threads, there are too many other threads.
* Author: ZhuangZi
* Class Name: public method Initialization
* Function: public method Initialization
* Details: public method Initialization
* Release: 1.0
* Date: 2013-03-22
* Note:
* When there are too many threads, there are too many other threads.
*/
$ (Function (){
/* 1. Missing focus verification */
$ ("# Code "). blur (callback); // 1. code is the ID of the control that you want to verify. your control must be followed by a control that receives error messages.
/* 2. Verify the token when submitting the ticket */
$ ("# Submit"). click (callback); // the ID of the submit button on your page
});
/**
* When there are too many threads, there are too many other threads.
* Author: ZhuangZi
* Class Name: The public method that verifies the unique identifier
* Function: unique verification
* Details: the unique ID and the submit button ID must be consistent with the following
* Release: 1.0
* Date: 2013-03-22
* Note:
* When there are too many threads, there are too many other threads.
*/
Function callback (){
Var slef = $ ("# code ");
Var code = slef. val ();
Var submit = $ ("# submit ");
Var flag = $ ("# flag"). val ();
If (null = code | "" = code ){
Slef.next().html ("The package ID cannot be blank! ");
Submit. attr ("disabled", true );
Return;
} Else {
If (! Code. match ("^ \ w + $ ")){
Slef.next().html ("the identifier consists of letters or underscores! ");
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 ("this ID already exists! ");
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 ('verification information error ');
}
});
}


Step 3 Page

The Code is as follows:




Download ID:



*




Step 4: Actions

The Code is as follows:


/**
*
* @ Author ZhuangZi
* @ Class com. hzdracom. action. YhaoPortalsDictionaryAction
* @ Method checkCodeOnly
* @ Directions verify the public method with the unique identifier
* @ Date 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 ();
}
}


Step 5: Methods in dao

The Code is as follows:


Public int checkCodeOnly (DictionaryBean bean) throws DataAccessException, Exception {
Object [] sqlParams = new Object [4];
Int index = 0;
String SQL = "";
/* Verify that the page flag is unique */
If (bean. getFlag (). equals ("1 ")){
SQL = "select count (1) from YHAO_PORTALS_PAGE where PAGE_FLAG =? ";
SqlParams [index] = bean. getCode ();
Index ++;
}
/* Verify that the ID of the type log is unique */
If (bean. getFlag (). equals ("2 ")){
SQL = "select count (1) from YHAO_PORTALS_DOWNTYPE where DOWNTYPE_FLAG =? ";
SqlParams [index] = bean. getCode ();
Index ++;
}
/* Verify that the download log ID is unique */
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.