JSP中擷取jstl中的資料

來源:互聯網
上載者:User

標籤:jstl   jsp   

我們在編程JSP時,有時會需要訪問jstl中的資料,或者說是el運算式中的資料。

比如,

<c:forEach    varStatus="data1" var="data" items="${alltemphotmeltdata}">
<tr>
<td>
${data.hNo }
</td>
<td>
${data.hDate }
</td>
<td>
${data.hHour }
</td>
<td>
${data.hEnd}
</td>
<td>
${data.hOperat }
</td>

</tr>

</c:forEach >

在上面程式碼片段中,若想擷取el運算式中的值進行處理時可以這樣做:

<td>
<%
  String HGPS_latitude=((HotmeltData)pageContext.getAttribute("data")).getHGPS_latitude().toString().replace(".","").replace("度",".").replace("分","");
  String HGPS_longitude=((HotmeltData)pageContext.getAttribute("data")).getHGPS_longitude().toString().replace(".","").replace("度",".").replace("分","");
  float latitude=Float.parseFloat(HGPS_latitude.substring(0, 2))+Float.parseFloat(HGPS_latitude.substring(2, HGPS_latitude.length()))/60;
  float longitude=Float.parseFloat(HGPS_longitude.substring(0, 3))+Float.parseFloat(HGPS_longitude.substring(3, HGPS_longitude.length()))/60;
%>
<a href="http://api.map.baidu.com/marker?location=<%=latitude%>,<%=longitude%>&title=定位&content=百度&output=html" target="_blank">地圖定位</a>

</td>

上面紅色的地方就是可以獲得el中的資料。

正如上面所說,可以利用
pageContext.getAttribute()
request.getAttribute()
session.getAttribute()
application.getAttribute()
得到值。 

又如:


<c:set var="a" value="hello a" scope="request" />
<c:set var="b" value="hello b"/>

<%
out.print(request.getAttribute("a") + "<br/>");
out.print(pageContext.getAttribute("b"));
%>

同理,也可以從jsp中得到變數放入jstl的變數中。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.