Ajax verifies user uniqueness and Ajax verifies user

Source: Internet
Author: User

Ajax verifies user uniqueness and Ajax verifies user

For beginners, learning about the uniqueness of Ajax verification users is to consolidate the basic knowledge of Ajax, Jquery, Json, and Struts2. The details are as follows:

Browsing:

Then we started,ProcedureAs follows:

1. First, we need to import the required packages and files.

Json package:

Struts2 package:

Introduce the jquery-2.1.1.min.js file.

<Script type = "text/javascript" src = "js/jquery-2.1.1.min.js"> </script>

2. Then, we need to configure the Struts2 filter in the web. xml file.

<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>

3. Then, write our login. jsp page. Of course, you can add some CSS styles to it to make it more beautiful. (I just did it, a little Low)

<Div class = "row"> 

4. Then, we begin to write the Action.

// Verify the uniqueness of the user. public void isexist () throws IOException {boolean exist = name. equals ("Zhang San"); JSONObject result = new JSONObject (); if (exist) {result. put ("exist", true);} else {result. put ("exist", false);} ServletActionContext. getResponse (). setContentType ("text/html; charset = UTF-8"); PrintWriter out = ServletActionContext. getResponse (). getWriter (); out. println (result. toString (); out. flush (); out. close ();}

5. Finally, compile the Struts. xml file.

<package name="user" namespace="/" extends="struts-default">   <action name="user_*" class="com.ddge.action.UserAction" method="{1}">  <result name="error">/login.jsp</result> </action></package>

Summary

Start deployment and test! The effect is out.

The above is all the content of this article, hoping to help you learn.

Related Article

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.