国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JSP > 正文

JSP中param標簽用法實例分析

2024-09-05 00:22:23
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了JSP中param標簽用法,以實例形式較為詳細的分析了param標簽的功能、定義與使用技巧,需要的朋友可以參考下

本文實例分析了JSP中param標簽用法。分享給大家供大家參考,具體如下:

Jsp中param標簽的使用

操作被用來以"名-值"對的形式為其他標簽提供附加信息。它和一起使用,方法如下:

復制代碼代碼如下:

其中,name為與屬性相關聯的關鍵詞,value為屬性的值。

1.配合使用

includeAction.jsp

 

 
  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=GB18030"
  4. <title>Include</title> 
  5. </head> 
  6. <body> 
  7. <%double i = Math.random();%> 
  8. <jsp:include page="come.jsp">//加載come.jsp 
  9. <jsp:param name="number" value="<%=i%>" />//傳遞參數 
  10. </jsp:include> 
  11. </body> 
  12. </html> 

come.jsp

 

 
  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=GB18030"
  4. <title>come</title> 
  5. </head> 
  6. <body bgcolor=cyan> 
  7. <Font Size=3> 
  8. <%//獲得includeAction.jsp傳來的值: 
  9. String str = request.getParameter("number"); 
  10. double n = Double.parseDouble(str); 
  11. %> 
  12. The value form includeAction is:<br> <%=n%> 
  13. </Font> 
  14. </body> 
  15. </html> 

2.配合使用

用戶登錄示例

login.jsp

 

 
  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=GB18030"
  4. <title>Login</title> 
  5. </head> 
  6. <body> 
  7. //由 checklogin.jsp處理表單數據 
  8. <form action="checklogin.jsp" method="get"
  9. <table> 
  10. <tr> 
  11. <td>Username:</td> 
  12. <td> //獲得參數"user",初始值為null 
  13. <input type="text" name="username" 
  14. value=<%=request.getParameter("user") %>> 
  15. </td> 
  16. </tr> 
  17. <tr> 
  18. <td>Password:</td> 
  19. <td> 
  20. <input type="password" name="password"
  21. </td> 
  22. </tr> 
  23. <tr> 
  24. <td> 
  25. <input type="submit" value="login"
  26. </td> 
  27. </tr> 
  28. </table> 
  29. </form> 
  30. </body> 
  31. </html> 

checklogin.jsp

 

 
  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=GB18030"
  4. <title>CheckLogin</title> 
  5. </head> 
  6. <body> 
  7. <% 
  8. //與login.jsp中name="username"對應 
  9. String name = request.getParameter("username"); 
  10. //與login.jsp中name="password"對應 
  11. String password = request.getParameter("password"); 
  12. if (name.equals("admin") && password.equals("admin")) { 
  13. %> 
  14. <jsp:forward page="success.jsp">//跳轉至success.jsp 
  15. <jsp:param name="user" value="<%=name%>" />//攜帶參數"user" 
  16. </jsp:forward> 
  17. <% 
  18. else { 
  19. %> 
  20. <jsp:forward page="login.jsp">//跳轉至login.jsp 
  21. <jsp:param name="user" value="<%=name%>" />//攜帶參數"user" 
  22. </jsp:forward> 
  23. <% 
  24. %> 
  25. </body> 
  26. </html> 

success.jsp

 

  1. <html> 
  2. <head> 
  3. <meta http-equiv="Content-Type" content="text/html; charset=GB18030"
  4. <title>Success</title> 
  5. </head> 
  6. <body> 
  7. Welcome,<%=request.getParameter("user")%>//獲得參數"user" 
  8. </body> 
  9. </html> 

希望本文所述對大家JSP程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 江城| 盐池县| 长乐市| 桂阳县| 哈尔滨市| 迁安市| 天镇县| 城固县| 格尔木市| 蓬溪县| 三原县| 昭觉县| 沧源| 岚皋县| 镇坪县| 武胜县| 长宁区| 台东市| 全州县| 茶陵县| 汝州市| 集贤县| 来凤县| 元谋县| 吉首市| 杭锦旗| 洛川县| 乡宁县| 襄樊市| 平远县| 纳雍县| 宝兴县| 寻乌县| 台安县| 台东市| 永康市| 临高县| 乌兰县| 怀柔区| 鄂伦春自治旗| 临漳县|