
{"id":2439,"date":"2020-10-29T10:16:12","date_gmt":"2020-10-29T02:16:12","guid":{"rendered":"http:\/\/admin.evshou.com\/?p=2439"},"modified":"2020-10-29T13:56:03","modified_gmt":"2020-10-29T05:56:03","slug":"2020javaweb%e6%95%99%e7%a8%8b%e4%b9%8bjsp%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2439","title":{"rendered":"2020javaweb\u6559\u7a0b\u4e4bJSP\u5e94\u7528"},"content":{"rendered":"<h3>2020javaweb\u6559\u7a0b\u4e4bJSP\u5e94\u7528<\/h3>\n<p><strong><span style=\"color: #ff0000;\">EL\u8868\u8fbe\u5f0f<\/span><\/strong><\/p>\n<p>\u76ee\u7684\uff1a\u7b80\u5316jsp\u4e2djava\u4ee3\u7801\u5f00\u53d1\uff0c\u4ee3\u66ff\u811a\u672c\u8868\u8fbe\u5f0f&lt;%=username%&gt;<br \/>\n\u5b83\u4e0d\u662f\u4e00\u79cd\u5f00\u53d1\u8bed\u8a00\uff0c\u800c\u662fjsp\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u4e00\u79cd\u89c4\u8303<br \/>\n\u683c\u5f0f\uff1a${username} \u7b49\u4ef7\u4e8e pageContext.findAttribute(name)<br \/>\n<!--more--><\/p>\n<p><strong><span style=\"color: #ff0000;\">\u83b7\u53d6\u7b80\u5355\u53c2\u6570<\/span><\/strong><\/p>\n<pre>&lt;%\r\n    pageContext.setAttribute(\"username\",\"admin\");\r\n    request.setAttribute(\"password\",\"admin888\");\r\n    session.setAttribute(\"mobile\",\"133\");\r\n    application.setAttribute(\"sex\",\"\u7537\");\r\n%&gt;\r\n&lt;%-- java\u811a\u672c\u8868\u8fbe\u5f0f--%&gt;\r\n&lt;%=request.getAttribute(\"password\")%&gt; &lt;br&gt;\r\n&lt;%-- EL\u8868\u8fbe\u5f0f --%&gt;\r\n${password} &lt;br&gt;\r\n&lt;%-- \u4e0d\u77e5\u9053\u5b58 \u54ea\u4e2a\u4f5c\u7528\u57df  \u60f3\u62ffapplication\u4f5c\u7528\u57df --%&gt;\r\n${applicationScope.sex}<\/pre>\n<p><strong><span style=\"color: #ff0000;\">\u83b7\u53d6\u5b9e\u4f53\u7c7b\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u503c<\/span><\/strong><\/p>\n<pre>&lt;%\r\n    Users users=new Users();\r\n    users.setUsername(\"admin\");\r\n    request.setAttribute(\"users\",users);\r\n%&gt;\r\n${users.username}<\/pre>\n<p><strong><span style=\"color: #ff0000;\">\u4f7f\u7528List\u548cMap\u96c6\u5408<\/span><\/strong><\/p>\n<pre>&lt;%\r\n    List&lt;String&gt; list=new ArrayList&lt;String&gt;();\r\n    list.add(\"A\");\r\n    list.add(\"B\");\r\n    list.add(\"C\");\r\n    list.add(\"D\");\r\n    request.setAttribute(\"list\",list);\r\n%&gt;\r\n${list.get(0)} ${list[2]} &lt;br&gt;\r\n\r\n&lt;%\r\n    Map&lt;String,String&gt; map=new HashMap&lt;String,String&gt;();\r\n    map.put(\"SH\",\"\u4e0a\u6d77\");\r\n    map.put(\"TJ\",\"\u5929\u6d25\");\r\n    map.put(\"GZ\",\"\u8d35\u5dde\");\r\n    request.setAttribute(\"map\",map);\r\n%&gt;\r\n${map.get(\"GZ\")} &lt;br&gt;\r\n${map.GZ} &lt;br&gt;\r\n${map[\"TJ\"]} &lt;br&gt;\r\n&lt;%-- \u83b7\u53d6\u96c6\u5408\u91cc\u6240\u6709\u7684\u503c --%&gt;\r\n${map.values()} &lt;br&gt;\r\n&lt;%-- \u83b7\u53d6\u96c6\u5408\u91cc\u6240\u6709\u7684\u952e --%&gt;\r\n${map.keySet()}<\/pre>\n<p><strong><span style=\"color: #ff0000;\">\u4f7f\u7528EL\u8868\u8fbe\u5f0f\u6267\u884c\u8fd0\u7b97<\/span><\/strong><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-2234\" src=\"\/wp-content\/uploads\/2020\/10\/29\/1.png\" alt=\"\" width=\"753\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2234\" src=\"\/wp-content\/uploads\/2020\/10\/29\/2.png\" alt=\"\" width=\"753\" \/><br \/>\n<img decoding=\"async\" class=\"alignnone size-full wp-image-2234\" src=\"\/wp-content\/uploads\/2020\/10\/29\/3.png\" alt=\"\" width=\"753\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #ff0000;\">empty\u5173\u952e\u5b57<\/span><\/strong><\/p>\n<p>empty\u5173\u952e\u53ea\u8981\u5185\u5bb9\u662f\u7a7atrue<\/p>\n<pre>&lt;%\r\n    String s=null;\r\n    String ss=\"\";\r\n    String sss=\" \";\r\n%&gt;\r\n${empty s}&lt;br&gt;\r\n${empty ss} &lt;br&gt;\r\n${empty sss} &lt;br&gt;<\/pre>\n<p><strong><span style=\"color: #ff0000;\">11\u4e2a\u9690\u5f0f\u5bf9\u8c61<\/span><\/strong><\/p>\n<p>JSP \u8868\u8fbe\u5f0f\u8bed\u8a00\u5b9a\u4e49\u4e86\u4e00\u7ec4\u9690\u5f0f\u5bf9\u8c61\uff0c\u5176\u4e2d\u8bb8\u591a\u5bf9\u8c61\u5728 JSP scriplet \u548c\u8868\u8fbe\u5f0f\u4e2d\u53ef\u7528\uff1a<\/p>\n<p><span style=\"color: #ff0000;\">pageContext\uff1a\u9875\u9762\u4e0a\u4e0b\u6587\uff0c\u53ef\u4ee5\u83b7\u53d6jsp\u4e2d\u5176\u4ed6\u516b\u4e2a\u5185\u7f6e\u5bf9\u8c61<\/span><\/p>\n<p><span style=\"color: #ff0000;\">pageScope\u3001requestScope\u3001sessionScope\u3001applicationScope\u8868\u793a\u56db\u4e2a\u57df\u5bf9\u8c61\u4e2d\u96c6\u5408<\/span><\/p>\n<p>param \u8868\u793arequest.getParameter(&#8220;username&#8221;); ${param.username}<\/p>\n<p>paramvalues \u8868\u793arequest.getPrameterValues(&#8220;hobby&#8221;); ${paramValues.hobby}<\/p>\n<p>header \u8868\u793a request.getHeader(&#8220;accept&#8221;); ${header.accept};<\/p>\n<p>headerValues \u8868\u793a request.getHeaderValues(&#8220;accept-encoding&#8221;); ${headerValues&#8221;accept-encoding&#8221;}<\/p>\n<p>cookie \u8868\u793a request.getCookies(); ${cookie.JSESSIONID}<\/p>\n<p>initParam \u8868\u793a ServletContext(application)\u521d\u59cb\u5316\u53c2\u6570<\/p>\n<pre>&lt;%\r\n    String username = request.getParameter(\"username\");\r\n%&gt;\r\n<span style=\"color: #ff0000;\">${param.username} &lt;br&gt;\r\n${paramValues.hobby[0]} &lt;br&gt; &lt;!-- \u83b7\u53d6\u591a\u9009\u6846\u7684\u503c --&gt;\r\n${header.Accept} &lt;!-- \u8df3\u8f6c\u8fc7\u6765\u8bf7\u6c42\u7684\u5934\u90e8\u4fe1\u606f\u6709\u54ea\u4e9b\u5185\u5bb9 --&gt;\r\n${headerValues[\"accept-encoding\"][0]} &lt;br&gt;\r\n${cookie.JSESSIONID} &lt;br&gt;\r\n${initParam.username}<\/span><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>2020javaweb\u6559\u7a0b\u4e4bJSP\u5e94\u7528 EL\u8868\u8fbe\u5f0f \u76ee\u7684\uff1a\u7b80\u5316jsp\u4e2djava\u4ee3\u7801\u5f00\u53d1\uff0c\u4ee3\u66ff\u811a\u672c\u8868\u8fbe\u5f0f&lt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2439","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2439"}],"version-history":[{"count":3,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2439\/revisions"}],"predecessor-version":[{"id":2443,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2439\/revisions\/2443"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}