The front-end form label sends a POST request, the server inherits the HttpServlet with the Java class, and returns the data

Source: Internet
Author: User

1. Form form submission:

<form action= "Http://localhost:8080/test/Login" method= "POST" >

User: <input type= "text" name= "username"/><br/>

Password: <input type= "password" name= "password"/><br/>

<input type= "Submit" value= "Login"/>

</form>

2, JS submitted:
(1) Added: <script type= "Text/javascript" src= "Assets/jquery-2.1.1.js" ></SCRIPT>, can be used in other, note to have $.post, some version does not ;

(2) var test={

Name: "Me",

Password: "Password"

};

$.post ("Http://localhost:8080/test/Login",

Test, function (text, status) {alert (text);});

3, Form+js submit:

The button in the form tag must be added: type= "button", followed by the same as above 2;

4. Server:

The Dopost () method in the Java class that inherits HttpServlet:

Request.setcharacterencoding ("UTF-8");

Response.setcharacterencoding ("UTF-8");

SYSTEM.OUT.PRINTLN ("Connect to Server" +request. GetParameter ("name") + "," +request. GetParameter ("Password" ));

Add Database Operations Database

PrintWriter out = response. getwriter ();

Out.write ("link Server success!"); //Return data to page

Out.close ();

The

Front-end form label sends a POST request, and the server inherits HttpServlet with the Java class and returns the data

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.