Use of struts and Ajax in SSH

Source: Internet
Author: User

Hard work The problem of nearly a week finally solved, so happy

In fact, it's very simple, first set up a map set in Controll.

    Private New Hashmap<>();          Public Map<string, object> getData () {            return  data;        }          Public void setData (map<string, object> data) {            this. Data= data;        }        

And then write the following code

        /*** Check email when registering *@return         * @throwsException*/                 Publicstring Selectemail () {String a=Us.selectemail (User.getemail ()); if(A.equals ("false") {data.put ("Result", "1"); }Else if(A.equals ("true") {data.put ("Result", "2"); }            return"Ajax"; }

Struts China code is as follows:

< Packagename= "Beforeuserinfo"namespace= "/user"extends= "Json-default">        <!--Query the mailbox when registering -        <Actionname= "Selectemail"class= "Com.zy.controll.UserControll"Method= "Selectemail">                    <resultname= "Ajax"type= "JSON">            <paramname= "root">Data</param>                </result>            </Action></ Package>

The page code is as follows:

          <Divclass= "Mask_content_body">                 <formID= "RegForm"Action= "${pagecontext.request.contextpath}/user/insertuser.action"onsubmit= "Javascript:return yz ()">                    <H3>New User Registration</H3>                    <inputtype= "Email"ID= "Regemail"placeholder= "Please enter the mailbox"name= "Email"onblur= "Yzemail ()"> <spanID= "Emailmsg"></span>                    <inputtype= "Password"ID= "REGPSW"placeholder= "Please enter password"name= "Password"onblur= "YZPW ()"><spanID= "Message1"></span>                                       <inputtype= "Password"ID= "Regpswagain"placeholder= "Please enter your password again"name= "Psw_again"onblur= "yzPW2 ()"><spanID= "Message2"></span>                    <DivID= "Yzm"class= "Form-inline">                    <inputtype= "text"name= "Yzm"ID= "Code_input"value=""style= "width:45%; display:inline-block;"placeholder= "Please enter verification code">                        <DivID= "V_container"style= "width:45%;height:40px;float:right;">                                                </Div>                                            </Div>                    <inputtype= "Submit"onclick= "return Commitregform ();"value= "Note & #x3000; book">                        <%-- <div>${error}</Div>--%><Div><H2ID= "AA"></H2></Div>                 </form>            </Div>

function Yzemail () {    var reg4 =/^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$/g;    var email = $ ("#regEmail"). Val ();    var password = $ ("#regPsw"). Val ();    if (!reg4.test (email)) {        $ ("#emailMsg"). HTML ("The mailbox is not formatted correctly!"). CSS ("Color", "red");        return false;    }    $ ("#emailMsg"). HTML ("");    $.post ("${pagecontext.request.contextpath}/user/selectemail.action", {        "email": $ ("#regEmail"). Val (),    },    function (data) {        alert (data.result);        if (data.result== "1") {                        $ ("#emailMsg"). HTML ("account already exists"). CSS ("Color", "red");            return false;        }    })    return true;}

Use of struts and Ajax in SSH

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.