HttpServeltRequest difference values and pass Model

HttpServletRequest request // output must form the front end of the form $ {user.id} ----- in the package javax.servlet.http.HttpServletRequest packets;

Model model // reception output must use the form $ {ul.value attribute name.} ----- in the form of package org.springframework.ui.Model; package

-----------------------------------------------------------

Model model, HttpServletRequest request, ModelMap map variable declaration

1.request.getSession () setAttribute ( "test" , " San"); // Get the first session, then the session into which the value (session is not closed, which can be taken in to)
2.request.setAttribute ( "test", "San"); // the request value into the inside (to get only values) in the same request in a request
3.map.addAttribute ( "test", "San"); // put value into the inside ModelMap
4.model.addAttribute ( "test", "San"); // put the value inside Model


Corresponding to the above values ​​is:

1.request.getSession().getAttribute("test")

2.request.getAttribute("test")

3.${test}

4.${test}

Note that $ {test} The way these four values ​​are applicable, but different values ​​of priority, take the Model and ModelMap, Model and ModelMap the same thing, who will take the final assignment who then is a request, and finally obtain from the session

 

There are several points to note and explain:

1. On request request lifecycle: send a connection request - receive a reply to this request on the request fails, put the value inside will take less than a;

2. different session, as long as the session is not the end of the session, session there will always exist a value (the value to be used in different requests a page we generally put in session)

3. However, session where the value will be replaced, for example:

request.getSession().setAttribute("test", "张三");

request.getSession().setAttribute("test", "李四");

In this case the attribute value corresponding to the session on the test into the "John Doe"

4. The corresponding four kinds of the above, there is replaced

Guess you like

Origin www.cnblogs.com/yunianzeng/p/11980083.html