标签:text doc mod 处理 equals ext 取值 sch sys
SpringMVC带数据给jsp页面
第一种方式:通过request域
java:用HttpServletRequest request传值
request.setAttribute("user", username);
request.setAttribute("password", password);存值
@RequestMapping(value="test1") public String test1(String username,String password,HttpServletRequest request) { request.setAttribute("user", username); request.setAttribute("password", password); if("admin".equals(username)&&"123".equals(password)) { //登录成功 return "success"; } else { //登录失败 System.out.println(username); return "fail"; } }
取值:在跳转到的success.jsp页面中写: ${requestScope.user }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <% String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort() +request.getContextPath()+"/"; %> <!DOCTYPE html> <html> <head> <base href="<%=basePath %>"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>new jsp</title> </head> <body> <h1>登录成功</h1> <!-- 通过request域保存数据 --> ${requestScope.user } </body> </html>
第二种方式:通过Model带数据
标签:text doc mod 处理 equals ext 取值 sch sys
原文地址:https://www.cnblogs.com/lonske/p/9125024.html