两个页面间传参
index.jsp
将参数提交到 TestParam.jsp 页面
<%@page contentType="text/html"%>
<%@page 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>JSP Page</title>
</head>
<body>
<form action=TestParam.jsp method=post>
Name:<input type="text" name="name" /><br>
EmpID:<input type="text" name="ID" /><br>
First Language: <input type="text" name="lang" /><br>
Second Language: <input type="text" name="lang" /><br>
<input type="submit" value="Submit" name="btnSubmit" />
</form>
</body>
</html>
TestParam.jsp
本页面负责接收参数,有两种方案
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>方法1:Using Scriplet</h1>
Employee name is: ${param.name}<br>
Employee ID is: ${param.ID}<br>
Employee knows ${param.lang}<br>
Employee knows ${paramValues.lang[0]} and ${paramValues.lang[1]} <br>
My Email is: ${initParam.myEmail}
<br>
<h5>方法2:Using Scriplet</h5>
<%
String name = request.getParameter("name");
String ID = request.getParameter("ID");
out.print("The Name :" + name + " ID:" + ID);
%>
</body>
</html>
设置页面内设置属性值
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1> Smart Softwares Inc. </h1>
<h3>Employee Information</h3>
<jsp:useBean id="Employee" class="pack.EmployeeBean" scope="application" />
<jsp:setProperty name="Employee" property="firstName" value="Lucy" />
<jsp:setProperty name="Employee" property="lastName" value="Lu" />
<jsp:setProperty name="Employee" property="designation" value="Software Developer" />
<!--usjng EL Expression to print the value for BEan Properties-->
First Name: ${Employee.firstName}<br>
Last Name: ${Employee.lastName}<br>
Designation: ${Employee.designation}
</body>
</html>