Get data from Jstl in JSP

Source: Internet
Author: User

When we are programming jsps, we sometimes need to access the data in the Jstl, or the data in the El expression.

Like what

<c:foreach    varstatus= "data1" var= "Data" items= "${alltemphotmeltdata}";
<tr>
<td>
${data.hno}
</td>
<td>
${data.hdate}
</td>
<td>
${data.hhour}
</td>
Span style= "White-space:pre" > <td>
${data.hend}
</td>
<td>
${data.hoperat}
</td>

</tr>

</c:foreach >

In the preceding code snippet, you can do this if you want to get the value in the El expression for processing:

<td>
<%
String hgps_latitude= ((hotmeltdata)Pagecontext.getattribute ("Data")).Gethgps_latitude (). toString (). Replace (".", ""). Replace ("degrees", "."). Replace ("Min", "" ");
String hgps_longitude= ((hotmeltdata)Pagecontext.getattribute ("Data")). Gethgps_longitude (). toString (). Replace (".", ""). Replace ("degrees", "."). Replace ("Min", "" ");
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= Positioning & content= Baidu &output=html "target=" _blank "> Map positioning </a>

</td>

The red part of the above is the data in El can be obtained.

As mentioned above, you can use
Pagecontext.getattribute ()
Request.getattribute ()
Session.getattribute ()
Application.getattribute ()
Get the value.

Another example:


<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"));
%>

In the same vein, you can get variables from the JSP into the JSTL variable.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.