在JSP中提供了EL表达式,可以快速的从web容器(page、request、session、ServletContext)中取出数据。
EL表达式的格式:
${在域中保存的数据的key值 }
request.setAtttribute(“username”,”zhangsan”)
如:${requestScope.username}
相当于 request.getAttribute(“username”)
【演示】
demo.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<% request.setAttribute("username", "张三"); %>
${username }
</body>
</html>
浏览器输入:http://localhost:8080/servlet/demo.jsp
浏览器显示:张三