SPRINGMVC, front-end JSP package parameters, binding parameters, passing parameters to the background controller process detailed 123

Source: Internet
Author: User

Front-to-back process: front desk jsp, background: Controller layer,service business layer,DAO data access layer, database model layer.

From the above process, the foreground JSP data, want to participate in the background of business logic operations, the key is to first put the foreground JSP data to the backstage controller. This key point involves a term called " binding Parameters " (or " bound data "), that is, how to bind the data in the foreground JSP to the parameters of the method in the background controller class.

In Springmvc, the "binding parameters" process requires a front-end JSP and a backend controller to be completed together:

1, the front desk JSP needs to do: Provide input box <input type= "text" name= "UserName" > or drop-down box <select name= "Province" > or radio box <input type= "Radio" name= "Sex" > or check box <checkbox name= "Hobbies", which is used to save multiple data entered by the user, This type of page tag element must be prefixed with the name attribute, indicating that this data is set as the request parameter (Request.setparameter ("UserName", user-entered user name), all encapsulated in the request, Then send a controller to the backend;

2, backstage controller needs to do: Controller receives request, automatically through Getrequest.getparameter ("UserName"), Request.getparameter ("sex") ... To remove multiple request parameters, how do you know which request parameter corresponds to which parameter of the method in the Controller class? This requires annotation @RequestPam: Before each parameter of the method in the Controller class, be sure to add the annotation @requestparam (value= "UserName", Required=false).

The above two steps completed, the successful completion of the "binding parameters"-the foreground JSP data, passed to the backend controller.

SPRINGMVC, front-end JSP package parameters, binding parameters, passing parameters to the background controller process detailed 123

Related Article

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.