其他分享
首页 > 其他分享> > servletAPI向Request对象共享数据

servletAPI向Request对象共享数据

作者:互联网

servletAPI向Request对象共享数据

@RequestMapping("/target2")
public String toTarget2(HttpServletRequest request) {
  String usrname = request.getParameter("usrname");
  String password = request.getParameter("password");
  System.out.println("usrname" + usrname + "/r" + "password" + password);
  request.setAttribute("testRequestScope","ok");
  return "target2";
}
public String toTarget2(HttpServletRequest request) {                      自动装配request对象
request.setAttribute("testRequestScope","ok");                             向Request对象共享数据
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<h1>success!</h1>
<p th:text="${testRequestScope}"></p>
</body>
</html>
<p th:text="${testRequestScope}"></p>                                   使用Request域对象中的数据

标签:servletAPI,usrname,String,对象,Request,request,共享,password
来源: https://www.cnblogs.com/new228666/p/16389790.html