User registration record string

Source: Internet
Author: User

How to save user input information is involved today. Some code is attached here,

Problem: on page A, the user fills in the user information and submits the information to the server for verification. If the verification succeeds, the user jumps to another page. If not, the user returns the original page, the original information is still in use to prevent users from entering the information again.

Problem analysis: the request is only used to pass parameters between two pages. For example, after a page post or get information is transmitted to the server, the request can be sent through the servlet at this time. the getparameter method obtains information, but when this information is obtained and then the original page is returned, the information submitted on the first page cannot be obtained after the third page is obtained, therefore, you need to share information through the session. The implementation method is as follows:

Make full use of the different submission methods of the form: Get and post. Get is used to obtain the display information, and post is used to submit information. The implementation method is as follows:

Package COM. zhangwei; import Java. io. *; import javax. servlet. HTTP. *; public class loginservlet extends httpservlet {// process the GET request public void doget (httpservletrequest req, httpservletresponse res) {res. setcontenttype ("text/html; charset = GBK"); try {printwriter PW = res. getwriter (); // The output HTML code. Set the value in the form part to % S, user string formatting string html = "<HTML> <body> User Logon <form action = login method = post> Username: <input type = text name = username value = % S> <br> "+" nickname: <input type = text name = Name value = % S> <br> Email: <input type = text name = Mail value = % S> <br> "+" password: <input type = password name = passwd value = % S> <br> <input type = submit value = login> <br> </form> </body> 

After compilation, configure the Web. xml file and start the Tomcat server. If the user name entered is not root, the following page is returned:

When the user input information fails to pass the verification, the original page is successfully returned and the user input information is retained. At this time, the URL is still http: // localhost: 8080/sayhello/login,

When the verification is passed, the Account page is displayed, showing the user information:

In this implementation, make full use of the respective features of get and post: Get transfers a small amount of data, but the efficiency is high, the transmitted parameters will be explicitly displayed in the URL. the post transmission method has a large amount of data, but the efficiency is not high. The transmitted parameters are placed in the HTTP header, which is more secure than get. Therefore, it is generally used in the following scenarios:

Get is used to obtain data from the server, such as displaying user information and querying. When a user opens an address in a browser, the get method is called by default. post is generally used for the client to transmit data to the server. For example, if the user fills in the registered account password, the post is sent to the server for processing.

User registration record string

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.