java - How to use an HTML5 data attribute to get session attribute -


i'm new front end side of java ee , html5. have read use data attribute read through dom. how use session attribute set java. compared other methods such using hidden input.

<input id="sid" type="hidden" name="series" value="${sessionscope.series} />  var sid = document.getelementbyid("sid"), series; 

use this:

<div id="div1" data-special-value="${sessionscope.series}"></div> 

and attribute value like:

document.getelementbyid("div1").getattribute("data-special-value") 

or ( http://caniuse.com/dataset ):

document.getelementbyid("div1").dataset("special-value") 

or jquery:

$("#div1").attr("data-special-value") // or $("#div1").data("special-value") 

although i'm not sure storing session value on element right. it's not wrong, i'm wondering you'd need/use sessions. sessions appear once.

the data-* attributes more useful storing related data something. example, if loop through bunch of database records , print columns, want store row's database id once, you'd use:

<c:foreach items="${rows}" var="row">     <tr data-row-id="${row.id}">         <td>${row.name}</td>         <td>${row.description}</td>     </tr> </c:foreach> 

then if want original row.id value, it's stored in 1 place encompasses pertains (the columns). how/where use data-* attributes. of course, there many ideas/uses this.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -