標籤:isp charset get web idt play name include動作 分享
相關資料:
《21天學通Java Web開發》
結果總結:
1.用來傳遞參數,一般與<jsp:include>、<jsp:forward>聯合使用。
2.<jsp:param name="參數值" value="參數值"/>
3.name用來設定參數的名字。value用來設定參數的值。
<jsp:include>動作元素搭配<jsp:param>動作元素
contentDemo.jsp (單參數)
1 <%@ page language="java" contentType="text/html; charset=gb2312" %>2 <h2>被包含頁</h2>3 <p>接收到的參數</p>4 <%5 String strAge = request.getParameter("age");//接收參數6 %>7 <%-- 輸出參數內容 --%>8 <%="age參數值為:"+strAge %>
View Code
param1.jsp
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>包含JSP檔案並傳遞參數</title> 5 </head> 6 <body> 7 使用include動作元素包含一個包含JSP檔案,並傳遞參數<br> 8 <jsp:include page="contentDemo.jsp"> 9 <jsp:param name="age" value="19"/>10 </jsp:include>11 </body>12 </html>
View Code
contentDemo2.jsp (多參數)
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <h2>被包含頁</h2> 3 <p>接收到的參數</p> 4 <% 5 String strName = request.getParameter("name");//接收參數 6 String strAge = request.getParameter("age");//接收參數 7 String strSex = request.getParameter("sex");//接收參數 8 %> 9 <%-- 輸出參數內容 --%>10 <%="name參數值為:"+strName %>11 <%="age參數值為:"+strAge %>12 <%="sex參數值為:"+strSex %>
View Code
params.jsp
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>包含JSP檔案並傳遞多個參數</title> 5 </head> 6 <body> 7 使用include動作元素包含一個包含JSP檔案,並傳遞多個參數<br> 8 <jsp:include page="contentDemo2.jsp"> 9 <jsp:param name="name" value="Jame"/>10 <jsp:param name="age" value="19"/>11 <jsp:param name="sex" value="man"/>12 </jsp:include>13 </body>14 </html>
View Code
<jsp:forward>動作元素搭配<jsp:param>動作元素
ForwardedDemo.jsp (單參數)
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>跳轉到的頁面</title> 5 </head> 6 <body> 7 <h2>跳轉到的頁面</h2> 8 <p>接收到的參數:</p> 9 <%10 String strAge = request.getParameter("age");//接收參數11 %> 12 <%-- 輸出參數內容 --%>13 <%="age參數值為:" + strAge %>14 </body>15 </html>
View Code
paramforward.jsp
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>跳轉並傳遞參數</title> 5 </head> 6 <body> 7 使用forward動作元素跳轉到另一個JSP檔案,並傳遞參數<br> 8 <jsp:forward page="ForwardedDemo.jsp"> 9 <jsp:param name="age" value="19"/>10 </jsp:forward>11 </body>12 </html>
View Code
ForwardedDemo2.jsp (多參數)
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>跳轉到的頁面</title> 5 </head> 6 <body> 7 <h2>跳轉到的頁面</h2> 8 <p>接收到的參數:</p> 9 <%10 String strName = request.getParameter("name");//接收參數11 String strAge = request.getParameter("age");//接收參數12 String strSex = request.getParameter("sex");//接收參數13 %> 14 <%-- 輸出參數內容 --%>15 <%="name參數值為:" + strName %>16 <%="age參數值為:" + strAge %>17 <%="sex參數值為:" + strSex %>18 </body>19 </html>
View Code
paramforward2.jsp
1 <%@ page language="java" contentType="text/html; charset=gb2312" %> 2 <html> 3 <head> 4 <title>跳轉並傳遞參數</title> 5 </head> 6 <body> 7 使用forward動作元素跳轉到另一個JSP檔案,並傳遞參數<br> 8 <jsp:forward page="ForwardedDemo2.jsp"> 9 <jsp:param name="name" value="name"/>10 <jsp:param name="age" value="19"/>11 <jsp:param name="sex" value="man"/>12 </jsp:forward>13 </body>14 </html>
View Code
JAVA-JSP動作元素之param