JSP 即 Java Server Pages邑闲,是一種簡(jiǎn)化的 Servlet 設(shè)計(jì)算行,實(shí)現(xiàn)了在 Java 中使用 HTML 標(biāo)簽。JSP 作為一種動(dòng)態(tài)網(wǎng)頁(yè)技術(shù)標(biāo)準(zhǔn) 也是 Java EE 的標(biāo)準(zhǔn)苫耸,與Servlet 一樣州邢,實(shí)在服務(wù)器端執(zhí)行的。
常見動(dòng)態(tài)網(wǎng)站開發(fā)技術(shù)對(duì)比
- JSP:Java 平臺(tái)鲸阔,安全性高偷霉,適合開發(fā)大型、企業(yè)級(jí)的 Web 應(yīng)用程序褐筛;
- ASP.net:.Net 平臺(tái)类少,簡(jiǎn)單易學(xué),但安全性和跨平臺(tái)性差渔扎;
- PHP:簡(jiǎn)單高效硫狞,成本低、開發(fā)周期短晃痴,適合中小型企業(yè)的 Web 應(yīng)用開發(fā)(LAMP:Linux + Apache + MySQL + PHP)残吩。
頁(yè)面元素
指令
- page:位于 JSP 頁(yè)面頂端,一個(gè)頁(yè)面可以有多個(gè)倘核;
- include:將外部文件嵌入當(dāng)前 JSP 中泣侮,同時(shí)解析這個(gè)頁(yè)面中的 JSP 語(yǔ)句;
- taglib:使用標(biāo)簽庫(kù)定義新的自定義標(biāo)簽紧唱,在 JSP 頁(yè)面中啟用定制行為活尊。
page 指令
<%@ page
contentType="text/html;charset=UTF-8"
language="java"
import="java.util.*"
%>
其中 pageEncoding
是 JSP 文件本身的編碼,contentType
的 charset 是指服務(wù)端發(fā)給客戶端時(shí)的內(nèi)容編碼漏益,contentType
更常用蛹锰。
注釋
JSP 中的注釋有三種
- HTML 注釋(客戶端/瀏覽器可見)
- JSP 注釋(客戶端不可見)
- JSP 腳本注釋
<!-- HTML 注釋 -->
<%-- JSP 注釋 --%>
<%
// 單行注釋
/*
多行注釋
*/
%>
腳本
在 JSP 頁(yè)面中執(zhí)行 Java 代碼。
實(shí)例:使用腳本輸出九九乘法表
<%!
void printMultiTable(JspWriter out) throws Exception {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++)
out.println(i + "*" + "=" + i * j + " ");
out.println("<br>");
}
}
%>
<% printMultiTable(out); %>
聲明
在 JSP 頁(yè)面中定義變量或方法
<%!
String name = "ywh";
Integer age = 16;
String getDesc(String name, Integer age) {
return "name: " + name + ", age: " + age.toString();
}
%>
表達(dá)式
在 JSP 頁(yè)面中執(zhí)行表達(dá)式绰疤,注意不能有分號(hào)铜犬。
實(shí)例:使用表達(dá)式打印九九乘法表
<%!
String printMultiTable() {
String s = "";
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++)
s += i + "*" + "=" + i * j + " ";
s += "<br>";
}
return s;
}
%>
<!-- 下面這個(gè)是表達(dá)式 -->
<%=printMultiTable()%>
靜態(tài)內(nèi)容
...
生命周期
JSP 實(shí)際上是一種 Servlet 對(duì)象;通過 tomcat/ work/ Catalina/ localhost 目錄可以看到生成的 java 源代碼(包含 jsp 初始化轻庆、解析執(zhí)行的方法)癣猾,其生命周期:
- 用戶發(fā)出請(qǐng)求(如訪問 index.jsp)
- 服務(wù)端判斷用戶是否首次發(fā)起請(qǐng)求:
2.1 是,JSP 引擎把該 JSP 文件轉(zhuǎn)換成(先執(zhí)行構(gòu)造方法)一個(gè) Servlet 對(duì)象余爆,生成字節(jié)碼文件煎谍,并執(zhí)行jspInit()
,訪問字節(jié)碼文件龙屉;
2.2 否,直接訪問字節(jié)碼文件; - 解析執(zhí)行字節(jié)碼文件转捕,調(diào)用
jspService()
方法作岖。
jspService()
:用于處理客戶端請(qǐng)求,對(duì)于每個(gè)請(qǐng)求都創(chuàng)建一個(gè)新的線程來(lái)處理五芝,如果多個(gè)客戶端同時(shí)請(qǐng)求痘儡,則 JSP 引擎會(huì)創(chuàng)建多個(gè)線程(每個(gè)客戶端對(duì)應(yīng)一個(gè));使用多線程可以大大降低對(duì)系統(tǒng)的資源需求枢步,提高系統(tǒng)的并發(fā)量和減少響應(yīng)時(shí)間沉删。但也可能存在線程同步問題。由于該 Servlet 常駐于內(nèi)存醉途,響應(yīng)速度很快矾瑰。
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*"%>
<%@ page import="java.text.*" %>
<html>
<head>
<title>JSP</title>
</head>
<body>
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String s = sdf.format(new Date());
%>
today: <%=s%>
</body>
</html>
內(nèi)置對(duì)象
JSP 內(nèi)置對(duì)象是 Web 容器創(chuàng)建的一組對(duì)象,不使用 new 關(guān)鍵字就可以使用的內(nèi)置對(duì)象隘擎。
- out
- request
- response
- session
- application
- Page, PageContext, exception, config
out 對(duì)象
out 對(duì)象是緩沖區(qū)(內(nèi)存的一塊保存臨時(shí)數(shù)據(jù)的區(qū)域)相關(guān)的 JspWriter
類的實(shí)例殴穴,向客戶端輸出內(nèi)容的對(duì)象。
<body>
<%
out.println("<h2>靜夜思</h2>");
out.println("床前明月光<br>");
out.println("疑是地上霜<br>");
out.flush();
//out.clear(); //這里會(huì)拋出異常货葬。
out.clearBuffer(); //這里不會(huì)拋出異常采幌。
out.println("舉頭望明月<br>");
out.println("低頭思故鄉(xiāng)<br>");
%>
緩沖區(qū)大小:<%=out.getBufferSize() %>byte<br>
緩沖區(qū)剩余大姓鹜啊:<%=out.getRemaining() %>byte<br>
是否自動(dòng)清空緩沖區(qū):<%=out.isAutoFlush() %><BR>
</body>
request 對(duì)象
客戶端請(qǐng)求信息被封裝在 request 對(duì)象中休傍,是 HttpServletRequest
類的實(shí)例。request 對(duì)象具有請(qǐng)求域蹲姐,即完成客戶端的請(qǐng)求之前該對(duì)象會(huì)一直有效磨取。
<body>
<h1>request內(nèi)置對(duì)象</h1>
<%
request.setCharacterEncoding("utf-8"); // 無(wú)法解決URL傳遞中文出現(xiàn)的亂碼問題,需要修改 Tomcat 配置文件
request.setAttribute("password", "123456");
%>
用戶名:<%=request.getParameter("username") %><br>
愛好 :<%
if (request.getParameterValues("favorite") != null) {
String[] favorites = request.getParameterValues("favorite");
for (int i = 0; i < favorites.length; i++) {
out.println(favorites[i] + " ");
}
}
%> <br>
密碼:<%=request.getAttribute("password") %><br>
請(qǐng)求體的MIME類型:<%=request.getContentType() %><br>
協(xié)議類型及版本號(hào): <%=request.getProtocol() %><br>
服務(wù)器主機(jī)名 :<%=request.getServerName() %><br>
服務(wù)器端口號(hào):<%=request.getServerPort() %><BR>
請(qǐng)求文件的長(zhǎng)度 :<%=request.getContentLength() %><BR>
請(qǐng)求客戶端的IP地址:<%=request.getRemoteAddr() %><BR>
請(qǐng)求的真實(shí)路徑:<%=request.getRealPath("request.jsp") %><br>
請(qǐng)求的上下文路徑:<%=request.getContextPath() %><BR>
</body>
解決 URL 傳遞中文亂碼問題淤堵,修改 Tomcat 配置文件:
<Connector port="8888"
...
URIEncoding="utf-8"
/>
response 對(duì)象
包含了響應(yīng)客戶請(qǐng)求的有關(guān)信息寝衫,是 HttpServletResponse
類的實(shí)例,但在 JSP 中很少使用拐邪。reponse
對(duì)象具有頁(yè)面作用域(只對(duì)某次訪問有效慰毅,其他頁(yè)面的 response
對(duì)當(dāng)前頁(yè)面無(wú)效)。
<%@ page language="java" import="java.util.*,java.io.*" contentType="text/html; charset=utf-8" %>
<%
response.setContentType("text/html;charset=utf-8"); //設(shè)置響應(yīng)的MIMI類型
out.println("<h1>response內(nèi)置對(duì)象</h1>");
out.println("<hr>");
// out.flush();
PrintWriter outer = response.getWriter(); //獲得輸出流對(duì)象
outer.println("大家好扎阶,我是response對(duì)象生成的輸出流outer對(duì)象");
// response.sendRedirect("reg.jsp"); //請(qǐng)求重定向
// 請(qǐng)求重定向
// response.sendRedirect("request.jsp");
// 請(qǐng)求轉(zhuǎn)發(fā)
request.getRequestDispatcher("request.jsp").forward(request, response);
%>
- 請(qǐng)求重定向:客戶端行為汹胃,
response.sendRedirect()
,本質(zhì)上是兩次請(qǐng)求东臀,前一次請(qǐng)求對(duì)象不會(huì)保存着饥,地址欄 URL 會(huì)改變; - 請(qǐng)求轉(zhuǎn)發(fā):服務(wù)端行為惰赋,
response.getRequestDispatcher().forward(req, resp);
是一次請(qǐng)求宰掉,轉(zhuǎn)發(fā)后請(qǐng)求對(duì)象會(huì)保存呵哨,地址欄的 URL 不會(huì)改變。
session 對(duì)象
在服務(wù)端存儲(chǔ)的轨奄、不同客戶端與服務(wù)端一次會(huì)話的信息(時(shí)間概念)孟害,第一次 JSP 頁(yè)面被裝載時(shí)自動(dòng)創(chuàng)建 session
對(duì)象,是 HttpSession
類的實(shí)例挪拟,完成會(huì)話期管理(從打開瀏覽器訪問服務(wù)端到關(guān)閉瀏覽器)挨务。
生命周期:在 Tomcat 后臺(tái)管理 http://localhost:8080/manager
中可以查看 Session 存儲(chǔ)情況。
- 創(chuàng)建:第一次訪問某個(gè) JSP 或者 Servlet 時(shí)候玉组,服務(wù)器會(huì)為當(dāng)前會(huì)話創(chuàng)建一個(gè) SessionId谎柄,每次客戶端向服務(wù)端發(fā)送請(qǐng)求時(shí),都會(huì)將此 SessionId 攜帶過去惯雳,服務(wù)端會(huì)對(duì)此 SessionId 進(jìn)行校驗(yàn)朝巫;
- 活動(dòng):某次會(huì)話中通過超鏈接打開新頁(yè)面屬于同一次會(huì)話,只要當(dāng)前會(huì)話頁(yè)面沒有關(guān)閉吨凑,重新打開新的窗口訪問同一項(xiàng)目資源也是同一次會(huì)話(除非所有頁(yè)面關(guān)閉再重新創(chuàng)建)捍歪;
- 銷毀:調(diào)用
session.invalidate()
方法、Session 過期(超時(shí))鸵钝、服務(wù)器重啟都會(huì)銷毀對(duì)象糙臼。
關(guān)于 session
對(duì)象:
- Tomcat 默認(rèn)
session
超時(shí)時(shí)間為 30min; - 設(shè)置超時(shí)時(shí)間:在代碼中設(shè)置
session.setMaxInactiveInterval(xxx); // 秒
恩商,或修改 Tomcat 配置文件 web.xml
<session-config>
<session-timeout>10</session-timeout>
</session-config> <!-- 單位:分 -->
page1
<body>
<%
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
Date d = new Date(session.getCreationTime());
session.setAttribute("username", "admin");
session.setAttribute("password", "123456");
session.setAttribute("age", 20);
//設(shè)置當(dāng)前session最大生成期限單位是秒
//session.setMaxInactiveInterval(10);//10秒鐘
%>
Session創(chuàng)建時(shí)間:<%=sdf.format(d)%><br>
Session的ID編號(hào):<%=session.getId()%><BR>
從Session中獲取用戶名:<%=session.getAttribute("username") %><br>
<a href="session_page2.jsp" target="_blank">跳轉(zhuǎn)到Session_page2.jsp</a>
</body>
page2
<body>
<hr>
<%
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
//Date d = new Date(session.getCreationTime());
//session.setAttribute("username", "admin");
%>
Session的ID編號(hào):<%=session.getId()%><BR>
從Session中獲取用戶名:<%=session.getAttribute("username") %><br>
Session中保存的屬性有:
<%
String[] names = session.getValueNames();
for (int i = 0; i < names.length; i++) {
out.println(names[i] + " ");
}
%>
</body>
application 對(duì)象
- 是
ServletContext
類的實(shí)例变逃,實(shí)現(xiàn)了用戶間數(shù)據(jù)共享,可存放全局變量怠堪; - 創(chuàng)建于服務(wù)器啟動(dòng)揽乱,終止于服務(wù)器關(guān)閉(服務(wù)器啟動(dòng)關(guān)閉決定
application
對(duì)象); - 在用戶前后連接粟矿、或不同用戶之間的連接中凰棉,可以對(duì)
application
對(duì)象的同一屬性進(jìn)行操作; - 任何地方對(duì)
application
對(duì)象屬性的操作陌粹,都影響其他用戶對(duì)此的訪問撒犀。
<body>
<%
application.setAttribute("city", "北京");
application.setAttribute("postcode", "10000");
application.setAttribute("email", "lisi@126.com");
%>
所在城市是:<%=application.getAttribute("city") %><br>
application中的屬性有:<%
Enumeration attributes = application.getAttributeNames();
while (attributes.hasMoreElements()) {
out.println(attributes.nextElement() + " ");
}
%><br>
JSP(SERVLET)引擎名及版本號(hào):<%=application.getServerInfo() %><br>
</body>
page 對(duì)象
指向當(dāng)前 JSP 頁(yè)面本身,類似類中的 this
指針掏秩,是 java.lang.Object
類的實(shí)例或舞。
pageContext 對(duì)象
- 提供了對(duì) JSP 頁(yè)面內(nèi)所有對(duì)象及命名空間的訪問(匯集了頁(yè)面中的所有功能);
- 可以訪問到本頁(yè)所在的 Session蒙幻,可以取本頁(yè)所在的
application
的某一屬性值映凳; - 本類名也為
pageContext
。
<body>
<h1>pageContext內(nèi)置對(duì)象</h1>
<hr>
用戶名是:<%=pageContext.getSession().getAttribute("username") %><br>
<%
// 跳轉(zhuǎn)到注冊(cè)頁(yè)面
// pageContext.forward("reg.jsp");
pageContext.include("include.jsp");
%>
</body>
config 對(duì)象
在 Servlet 初始化時(shí)邮破,JSP 引擎向它傳遞信息使用到 config
對(duì)象诈豌,此信息包括 Servlet 初始化時(shí)用到的參數(shù)(通過屬性名稱和屬性值構(gòu)成)以及服務(wù)器的基本信息(通過傳遞一個(gè) ServletContext
對(duì)象)仆救,常用方法:
-
getServletContext
:返回含有服務(wù)器相關(guān)信息的 ServletContext 對(duì)象; -
getInitParameter
:返回初始化參數(shù)的值队询; -
getInitParameterNames
:返回 Servlet 初始化所需所有參數(shù)值的枚舉派桩; - ...
exception 對(duì)象
頁(yè)面運(yùn)行異常時(shí)產(chǎn)生,當(dāng)一個(gè) JSP 頁(yè)面要應(yīng)用此對(duì)象蚌斩,必須把 isErrorPage
設(shè)置為 true
,否則無(wú)法通過編譯范嘱,實(shí)際上是 java.lang.Throwable
的對(duì)象送膳。
test_page
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" errorPage="exception.jsp" %>
<body>
<%
System.out.println(100 / 0); //拋出運(yùn)行時(shí)異常,算數(shù)異常
%>
</body>
error_page
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" isErrorPage="true" %>
...
<body>
異常的消息是:<%=exception.getMessage()%><BR>
異常的字符串描述:<%=exception.toString()%><br>
</body>
JSP 實(shí)現(xiàn)用戶登錄
dologin.jsp:登錄邏輯處理
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
String username = "";
String password = "";
request.setCharacterEncoding("utf-8"); // 防止中文亂碼
username = request.getParameter("username");
password = request.getParameter("password");
if ("admin".equals(username) && "admin".equals(password)) { // 如果用戶和密碼都等于 admin 則登錄成功丑蛤,服務(wù)器轉(zhuǎn)發(fā)叠聋;失敗則重定向到失敗頁(yè)面
session.setAttribute("loginUser", username);
request.getRequestDispatcher("login_success.jsp").forward(request, response);
} else {
response.sendRedirect("login_failure.jsp");
}
%>
login.jsp:登錄請(qǐng)求頁(yè)面
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<body>
<div id="container">
<div class="logo">
<a href="#"><img src="assets/logo.png" alt=""/></a>
</div>
<div id="box">
<form action="dologin.jsp" method="post">
<p class="main">
<label>用戶名: </label><input name="username" value=""/>
<label>密碼: </label><input type="password" name="password" value="">
</p>
<p class="space">
<input type="submit" value="登錄" class="login" style="cursor: pointer;"/>
</p>
</form>
</div>
</div>
</body>
login_success.jsp:登錄成功轉(zhuǎn)發(fā)頁(yè)面
<body>
<div id="container">
<div class="logo">
<a href="#"><img src="assets/logo.png" alt=""/></a>
</div>
<div id="box">
<%
String loginUser = "";
if (session.getAttribute("loginUser") != null)
loginUser = session.getAttribute("loginUser").toString();
%>
歡迎您<font color="red"><%=loginUser%>
</font>,登錄成功!
</div>
</div>
</body>
login_failure.jsp:登錄失敗重定向頁(yè)面
<div id="container">
<div class="logo">
<a href="#"><img src="assets/logo.png" alt=""/></a>
</div>
<div id="box">
登錄失斒芄碌补!請(qǐng)檢查用戶或者密碼!<br>
<a href="login.jsp">返回登錄</a>
</div>
</div>
JSP 狀態(tài)管理
HTTP 協(xié)議的無(wú)狀態(tài)性:瀏覽器發(fā)送請(qǐng)求給服務(wù)器,服務(wù)器響應(yīng)客戶端請(qǐng)求棉饶,但當(dāng)同一瀏覽器再次發(fā)送請(qǐng)求給服務(wù)器時(shí)厦章,服務(wù)器并不知道它就是之前那個(gè)瀏覽器。
保存用戶狀態(tài)的兩大機(jī)制:
- Cookie
- Session
實(shí)例:JSP 中使用 Cookie 實(shí)現(xiàn)用戶登錄
dologin.jsp
<%@ page language="java" import="java.util.*,java.net.*" contentType="text/html; charset=utf-8" %>
<body>
<%
request.setCharacterEncoding("utf-8");
String[] isUseCookies = request.getParameterValues("isUseCookie");
if (isUseCookies != null && isUseCookies.length > 0) { // 首先判斷用戶是否選擇了記住登錄狀態(tài)
String username = URLEncoder.encode(request.getParameter("username"), "utf-8"); // 把用戶名和密碼保存在Cookie對(duì)象里面
String password = URLEncoder.encode(request.getParameter("password"), "utf-8"); // 使用URLEncoder解決無(wú)法在Cookie當(dāng)中保存中文字符串問題
Cookie usernameCookie = new Cookie("username", username);
Cookie passwordCookie = new Cookie("password", password);
usernameCookie.setMaxAge(864000);
passwordCookie.setMaxAge(864000); // 設(shè)置最大生存期限為10天
response.addCookie(usernameCookie);
response.addCookie(passwordCookie);
}
else {
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie c : cookies) {
if (c.getName().equals("username") || c.getName().equals("password")) {
c.setMaxAge(0); // 設(shè)置Cookie失效
response.addCookie(c); // 重新保存照藻。
}
}
}
}
%>
<a href="users.jsp" target="_blank">查看用戶信息</a>
</body>
login.jsp
<%@ page language="java" import="java.util.*,java.net.*" contentType="text/html; charset=utf-8" %>
<body>
<%
request.setCharacterEncoding("utf-8");
String username = "";
String password = "";
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie c : cookies) {
if (c.getName().equals("username"))
username = URLDecoder.decode(c.getValue(), "utf-8");
if (c.getName().equals("password"))
password = URLDecoder.decode(c.getValue(), "utf-8");
}
}
%>
<form name="loginForm" action="dologin.jsp" method="post">
<table>
<tr>
<td>用戶名:</td>
<td><input type="text" name="username" value="<%=username %>"/></td>
</tr>
<tr>
<td>密碼:</td>
td><input type="password" name="password" value="<%=password %>"/></td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="isUseCookie" checked="checked"/>十天內(nèi)記住我的登錄狀態(tài)</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="登錄"/><input type="reset" value="取消"/></td>
</tr>
</table>
</form>
</body>
users.jsp
<%@ page language="java" import="java.util.*,java.net.*" contentType="text/html; charset=utf-8" %>
<body>
<%
request.setCharacterEncoding("utf-8");
String username = "";
String password = "";
Cookie[] cookies = request.getCookies();
if (cookies != null && cookies.length > 0) {
for (Cookie c : cookies) {
if (c.getName().equals("username"))
username = URLDecoder.decode(c.getValue(), "utf-8");
if (c.getName().equals("password"))
password = URLDecoder.decode(c.getValue(), "utf-8");
}
}
%><br>
用戶名:<%=username %><br>
密碼:<%=password %><br>
</body>
指令和動(dòng)作
include 指令與動(dòng)作
date.jsp
<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%@ page import="java.text.*" %>
<%
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
String s = sdf.format(d);
out.println(s);
%>
include_command.jsp
<%@ include file="date.jsp" %>
include_action.jsp
<jsp:include page="date.jsp" flush="false"/>
forward 動(dòng)作
user.jsp
<body>
<%
request.setCharacterEncoding("utf-8");
String username = "";
String password = "";
String email = "";
if (request.getParameter("username") != null)
username = request.getParameter("username");
if (request.getParameter("password") != null)
password = request.getParameter("password");
if (request.getParameter("email") != null)
email = request.getParameter("email");
%>
用戶名:<%=username %><br>
密碼:<%=password %><br>
電子郵箱:<%=email %><br>
</body>
login.jsp
<body>
<form name="loginForm" action="forward.jsp" method="post">
<table>
<tr>
<td>用戶名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>密碼:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="登錄"/></td>
</tr>
</table>
</form>
</body>
forward.jsp
<body>
<jsp:forward page="user.jsp"/>
<!--<% request.getRequestDispatcher("user.jsp").forward(request, response); %>-->
</body>
param 動(dòng)作
在 forward
中加入傳遞參數(shù)
<body>
<jsp:forward page="user.jsp">
<jsp:param value="admin@123.net" name="email"/>
<jsp:param value="888888" name="password"/>
</jsp:forward>
</body>