1、form.jsp

 

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTt1.jspML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 't1.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<%out.print("servlet的环境:"+config.getServletContext()); %>
<form action="jsp/el1.jsp" method="post">
<input type="text" name="name"/><br>
<input type="password" name="password"/><br>
<input type="submit" />
</form>
</body>
</html>

 

2、el1.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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'el1.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>

<body>
<!--EL表达式的基本用法 -->
<p>使用java代码获取用户名:<%=request.getParameter("name") %></p>
<!--使用EL表达式的两种方法输出参数是name和password的值 -->
<!--从其他页面传递的参数使用这种格式获取数据 -->
<p>使用EL表达式获取用户名:${param.name}</p>
<p>使用EL表达式获取用户名:${param["name"]}</p>
<p>使用EL表达式获取用户密码:${param.password}</p>
<p>使用EL表达式获取用户密码:${param["password"]}</p>
<!-- 输出结果为:${param.name}-->
${"${param.name}" }
<!-- 输出结果:qqqqq -->
${"qqqqqq" }
<!--EL表达式的存取范围:pageScope,requestScope,sessionScope,applicationScope -->
<!--1.存储数据 -->
<%session.setAttribute("session", "EL表达式!!!!"); %>
<!--2.获取session中的值 -->
通过java代码获取sessionScope的属性值:<%=session.getAttribute("session") %><br>
通过EL表达式获取sessionScope的属性值:${sessionScope.session }
<!--注:jsp的内置对象也是EL表达式的对象。可以使用 -->
</body>
</html>