How the servlet gets the data for the form
- Front-end pages submit data through form forms
-
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