EL表达式 requestScope initParam用法:

servlet:

package com.stono.servlet;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet7 extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("foo.person", "personFoo");
RequestDispatcher dispatcher = req.getRequestDispatcher("index045.jsp");
dispatcher.forward(req, resp);
}
}

jsp:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>045index</title>
</head>
<body>
${requestScope["foo.person"] }
<hr>
${initParam.email }
<hr>
${cookie }
</body>
</html>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<display-name>TestBootWeb</display-name>
<servlet>
<servlet-name>test7</servlet-name>
<servlet-class>com.stono.servlet.TestServlet7</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>test7</servlet-name>
<url-pattern>/test7.do</url-pattern>
</servlet-mapping>
<context-param>
<param-name>email</param-name>
<param-value>[email protected]</param-value>
</context-param>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>false</el-ignored>
</jsp-property-group>
</jsp-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
04-21 19:18