(v) Springmvc to obtain the data submitted by the form

Source: Internet
Author: User

8.1: Use request<formMethod= "POST"ID= "Form1"Action= "<%=request.getcontextpath ()%>/formdata/formdata_1">        <inputtype= "text"name= "username"value= "User name"/>        <inputtype= "checkbox"name= "Check_1"value= "check box 1"/>check box 1<inputtype= "checkbox"name= "Check_1"value= "check box 2"/>check box 2<inputtype= "checkbox"name= "Check_1"value= "check box 3"/>check box 3<inputtype= "Submit"value= "Submit"/>    </form>8.2: Using formal parameter Annotations<formMethod= "POST"ID= "Form1"Action= "<%=request.getcontextpath ()%>/formdata/formdata_2">        <inputtype= "text"name= "username"value= "User name"/>        <inputtype= "checkbox"name= "Check_1"value= "check box 1"/>check box 1<inputtype= "checkbox"name= "Check_1"value= "check box 2"/>check box 2<inputtype= "checkbox"name= "Check_1"value= "check box 3"/>check box 3<inputtype= "Submit"value= "Submit"/>    </form>8.3: Use objects to get<formMethod= "POST"ID= "Form1"Action= "<%=request.getcontextpath ()%>/formdata/formdata_3">        <inputtype= "text"name= "username"value= "User name"/>        <inputtype= "checkbox"name= "Check_1"value= "check box 1"/>check box 1<inputtype= "checkbox"name= "Check_1"value= "check box 2"/>check box 2<inputtype= "checkbox"name= "Check_1"value= "check box 3"/>check box 3<inputtype= "Submit"value= "Submit"/>    </form>    

Controller

 PackageCom.controller.formdata;Importjava.util.Arrays;ImportJavax.servlet.ServletContext;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse;Importjavax.servlet.http.HttpSession;Importorg.springframework.beans.factory.annotation.Autowired;ImportOrg.springframework.stereotype.Controller;Importorg.springframework.web.bind.annotation.RequestMapping;ImportOrg.springframework.web.bind.annotation.RequestParam;ImportOrg.springframework.web.servlet.ModelAndView;ImportCom.bean.UserBean; @Controller @requestmapping (Value= "/formdata") Public classFormData {@AutowiredPrivateHttpServletRequest request; @AutowiredPrivatehttpservletresponse response; @AutowiredPrivateHttpSession session; @AutowiredPrivateServletContext ServletContext; @RequestMapping (Value= "/formdata_1")     PublicModelandview formdata_1 ()throwsException { This. request.setcharacterencoding ("UTF-8"); String username= Request.getparameter ("username"); String[] Check_1= Request.getparametervalues ("Check_1");        SYSTEM.OUT.PRINTLN (username);        System.out.println (Arrays.aslist (check_1)); return NULL; } @RequestMapping (Value= "/formdata_2")     PublicModelandview formdata_2 (@RequestParam (name= "username") String username_2, string[] check_1)throwsException {System.out.println ("Formdata_2 Method");        System.out.println (username_2);        System.out.println (Arrays.aslist (check_1)); return NULL; }    /*** Similar to model-driven in struts * *@paramUserBean *@return     * @throwsException*/@RequestMapping (Value= "/formdata_3")     PublicModelandview formdata_3 (UserBean UserBean)throwsException {System.out.println ("Formdata_3 Method");        System.out.println (Userbean.getusername ());        System.out.println (Arrays.aslist (Userbean.getcheck_1 ())); return NULL; }}
Userbean.java
 Public classUserBeanImplementsSerializable {PrivateString username; Privatestring[] Check_1;  PublicString GetUserName () {returnusername; }     Public voidSetusername (String username) { This. Username =username; }     Publicstring[] Getcheck_1 () {returnCheck_1; }     Public voidsetcheck_1 (string[] check_1) { This. Check_1 =Check_1; }}












(v) Springmvc to obtain the data submitted by 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.