Added two page-value display functions for the last lesson Project +MVC Framework Learning Log

Source: Internet
Author: User

First, the modification of test2:

The misunderstanding of the last lesson: El expression ${loginname} is the one that receives the data.

Requirement: Add an input tag to the index page, set the Type property to add a text box that requires you to enter a piece of text to display in the text box on the response page after the jump.

Analysis: The process of implementing this function is to pass the value of a JSP page to the servlet server before being passed by the server to the page after the jump is displayed.

If you want to implement it, you need to use the GetParameter () method in business logic to get the value entered in index, and then use the SetAttribute () method to set the value. The code modified in the servlet is as follows:

String Loginadd = Req.getparameter ("Loginadd"); Req.setattribute ("Loginadd", Loginadd);

Second, the MVC framework

The full name of MVC is the Model View controller, which is the abbreviation for the models-view-controllerorganize your code with a separate approach to business logic, data, and interfaces, and aggregate business logic into a single component, without the need to rewrite business logic while improving and personalizing the interface and user interaction. The purpose of using MVC is to separate the implementation code for M and v so that the same program can use a different representation.

Supplemental content: (C exists to ensure the synchronization of M and V, once M is changed, V should be updated synchronously.) )

model is the part of your application that handles application data logic.
Typically, model objects are responsible for accessing data in the database.

View is the part of the application that handles the display of data.
Typically views are created from model data.

A controller is a part of an application that handles user interaction.
Usually the controller is responsible for reading data from the view, controlling user input, and sending data to the model.

Third, case analysis (V-C-M-C-V)

Project: SPRINGMMVC

Helloworldcontroller.java (excerpt)

@AutowiredHelloWorldService helloworldservice; @RequestMapping (value = "/", method = requestmethod.get) public String   Index (model) {return "HelloWorld";    } @RequestMapping (value = "/init", method = requestmethod.post) public String initlogin (UserBean Userbean,model Model) {    UserBean Result=helloworldservice.searchuser (UserBean); Model.addattribute ("UserBean", result); return "Login";

@Autowired can label member variables, methods, and constructors to complete the work of automatic Assembly

@? the requestmapping is accessed by matching the path URL to the corresponding page. Annotations used to process request address mappings, which can be used on classes or methods.

For example:@RequestMapping(Value= "/", method = requestmethod.get) Public String index (model model) {
return "HelloWorld"; }when the IE page request method is get, match by Root path and jump to the HelloWorld via the returnHelloWorld page. Then execute the Post form submission to init

@RequestMapping (value = "/init", method = requestmethod.post) public String initlogin (UserBean Userbean,model Model) {
UserBean Result=helloworldservice.searchuser (UserBean);
Model.addattribute ("UserBean", result);
return "Login";}

Create a bean to set the Get,set method for the Uesrid property

public class UserBean {private string Userid;public string GetUserId () {return userId;}  public void Setuserid (String userId) {This.userid=userid; }}

Create a HelloWorldService class to assign a value of Uesrid to test

public class HelloWorldService {public UserBean searchuser (UserBean frm) {frm.setuserid ("test");    return frm; }}

The last jump to the login page is to display the assigned value

${userbean.userid};

Added two page-value display functions for the last lesson Project +MVC Framework Learning Log

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.