I'm looking to set a variable based on some security for the user logged into and then use that value within JQuery.
This is the setting the variable:
<c:set var="hasResDetailAccess" value="false"/>
What JQuery would be used to retrive that vlaue
jQuery(document).ready(
function() {
var display = $(#frank).text();
});
Try printing the value in a hidden input an retrieve it from there:
<input type="hidden" value="<c:out value="${hasResDetailAccess}"/>" id="hasResDetailAccess">
and retrieve it with
var display = $('#hasResDetailAccess').val();
Actually what you are trying with <c:set>
and jQuery
both are different thing. <c:set>
is useful while translating jsp to servlet ie on server side and 'jQuery' is used to process value on the client side ie in the browser.
So if you want a variable within jQuery just add it to any scope ie request,session,context or application as per your requirement and retrieve it in jsp.
For example in Servlet
,
add
request.setAttribute("hasResDetailAccess",hasResDetailAccess);
And in JSP just put code as below,
jQuery(document).ready(
function() {
var hasResDetailAccess= ${hasResDetailAccess} ;
});
${hasResDetailAccess}
will fetch value of the variable regardless of the scope and set it to the jQuery
variable `hasResDetailAccess. And latter on you can retrieve that jQuery Variable in HTML page anywhere any point of time you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.