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

首頁 > 編程 > JSP > 正文

JSP中正則表達(dá)式用法實(shí)例

2024-09-05 00:22:24
字體:
供稿:網(wǎng)友

這篇文章主要介紹了JSP中正則表達(dá)式用法,實(shí)例分析了JSP中正則表達(dá)式的簡單使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了JSP中正則表達(dá)式用法。分享給大家供大家參考,具體如下:

 

 
  1. <%@ page language="java" import="java.util.*,cn.com.Person,cn.com.Adddress" pageEncoding="UTF-8"%> 
  2. <% 
  3. String path = request.getContextPath(); 
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
  5. %> 
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  7. <html> 
  8. <head> 
  9. <base href="<%=basePath%>"
  10. <title>My JSP 'El.jsp' starting page</title> 
  11. <meta http-equiv="pragma" content="no-cache"
  12. <meta http-equiv="cache-control" content="no-cache"
  13. <meta http-equiv="expires" content="0">  
  14. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"
  15. <meta http-equiv="description" content="This is my page"
  16. <!-- 
  17. <link rel="stylesheet" type="text/css" href="styles.css"
  18. --> 
  19. </head> 
  20. <body> 
  21. <% 
  22. String data="assd"
  23. request.setAttribute("data", data); 
  24. %> 
  25. <!-- 正則表達(dá)式,對于 Request傳過來的數(shù)據(jù)可以直接如下顯示 
  26. 相當(dāng)于:pageContext.findAttribute("data"); 
  27. 這是一般的方式 
  28. --> 
  29. ${data } 
  30. <br/> 
  31. <% 
  32. Person p=new Person(); 
  33. p.setName("name"); 
  34. request.setAttribute("person", p);  
  35. %> 
  36. <!-- 反射name屬性獲取這個(gè)值輸出  
  37. 數(shù)據(jù)通過JAVABean里傳過來的如下: 
  38. --> 
  39. ${person.name} 
  40. <br/> 
  41. <% 
  42. Person p2=new Person(); 
  43. Adddress add=new Adddress(); 
  44. add.setCity("NewYork"); 
  45. p2.setAddress(add); 
  46. request.setAttribute("p2", p2); 
  47. %> 
  48. <!-- 下面的是定義一個(gè)Person的類和一個(gè)Adddress的類 
  49. Person中私有屬性:private Adddress address; 
  50. 要獲取他的地址可以如下的方式來完成 
  51. 數(shù)據(jù)復(fù)雜的bean里面帶過來的如下: 
  52. --> 
  53. ${p2.address.city} 
  54. <br/> 
  55. <% 
  56. ArrayList list=new ArrayList(); 
  57. list.add(new Person("wy")); 
  58. list.add(new Person("wyy")); 
  59. list.add(new Person("wyyy")); 
  60. request.setAttribute("list", list); 
  61. %> 
  62. <!-- 集合帶過來的怎么獲取數(shù)據(jù)呢? --> 
  63. ${list[1].name } 
  64. <br/> 
  65. <% 
  66. Map map=new HashMap(); 
  67. map.put("1"new Person("aaaa")); 
  68. map.put("b"new Person("bbbb")); 
  69. map.put("c"new Person("cccc")); 
  70. map.put("d"new Person("dddd")); 
  71. request.setAttribute("map", map); 
  72. %> 
  73. <!--  
  74. Map集合帶過來的怎么獲取數(shù)據(jù)呢? 
  75. map集合的數(shù)據(jù)存放的時(shí)候id一般不要用數(shù)字:會出現(xiàn)500錯(cuò)誤 
  76. 但是用數(shù)字的話獲取方式如第二條 
  77. .號取不出來就用中括號[] 
  78. --> 
  79. ${map.b.name} 
  80. ${map['1'].name } 
  81. <br/> 
  82. <!-- 獲取當(dāng)前的web項(xiàng)目名 --> 
  83. ${pageContext.request.contextPath} 
  84. <a href="${pageContext.request.contextPath}/demo1.jsp" >點(diǎn)</a> 
  85. </body> 
  86. </html> 

希望本文所述對大家JSP程序設(shè)計(jì)有所幫助。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 信宜市| 秦皇岛市| 浠水县| 大石桥市| 石渠县| 佛教| 于田县| 古田县| 淅川县| 玉田县| 新绛县| 泗阳县| 思茅市| 育儿| 霍州市| 巴马| 林芝县| 麻江县| 万盛区| 剑河县| 藁城市| 防城港市| 西峡县| 桂东县| 临沭县| 澄迈县| 宁城县| 九台市| 亳州市| 漯河市| 威远县| 额敏县| 沿河| 永济市| 紫阳县| 丹棱县| 中卫市| 五大连池市| 日土县| 阳泉市| 惠东县|