How Java servlet gets the data for the form

Source: Internet
Author: User

How the servlet gets the data for the form
  1. Front-end pages submit data through form forms
  2. Server-side definition Servlet interface

        Public void DoPost(HttpServletRequest request,HttpServletResponse response) throws Servletexception,Ioexcption{    //Define a user information classUsers u= New User();String username;String Password;Date Birthday;String[] Favorites;    //Demo temporarily does not encapsulate the dataSimpledatefromate time= New simpledatefromate("Yyyy-mm-dd");    Try{        //Get a single parameterUsername= Request.GetParameter("username");Birthday=  Time.Parse(Request.GetParameter("Birthday");)//used to get parameters passed by multiple check buttonsFavorites= Request.getparametervalues("Favorites");        //Add data to the generated user object through the encapsulation method of the data        u.Setusername(username);        u.Setbirthday(birthday);        u.setfavorites(Favorites);        //When the request succeeds, similar redirect        Request.Getrequestdispatcher(".. /index ").forward(Request,Response;  //This inside is custom        //Jump to the request, response this two objects backward pass    }Catch(Exception e){        //Print the wrong information        e.Printstacktrace();    }   }

How Java servlet gets the data for the form

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.