In the Java Web development process, processing form data is an important part of the common is the form post processing a single piece of data, but also encountered one time to submit multiple data to the server, as follows:
JSP page is generally used in the loop Insert input box, and all the ID and name is the same prefix, convenient server access
1 < items= "${objlist}" var= "obj">2 < id = "key_${obj." Id} " name=" key_${obj. Id} "/>3</c:foreach>
Server-side Get parameter code:
1@RequestMapping (value = "/xxxsave", method =requestmethod.post)2 PublicString Paypropssave (FinalHttpServletRequest Request) {3 4 FinalEnumeration<string> enums =Request.getparameternames (); //Get request all parameters 5 6 FinalList<obj> objlist =NewArraylist<obj>();7 8 while(Enums.hasmoreelements ()) {9 FinalString paramname =enums.nextelement (). toString ();Ten if(Paramname.startswith ("Key_") {//filter all parameters starting with Key_ One FinalString Elementvalue =Request.getparameter (paramname); A Finalobj obj =NewObj (); - Obj.setid (elementvalue); - . the . - . - Objlist.add (props); - } + } - + objservice.saveobjlist (objlist); A ... at ... - ... - - return"XXX"; - -}
The above is the accumulation of work, if there is a problem, please discuss correct, reprint annotated address
Java handles bulk data submissions