Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  7] [ 7]  / answers: 1 / hits: 64341  / 13 Years ago, fri, october 28, 2011, 12:00:00

When loading a page, I have the following in my controller:



request.setAttribute(myAtt, Testing);


I want to access this in my JSP file. In the HTML section, I am familiar with using things like:



${myAtt} ${requestScope.myAtt}


and the like. However, I've never been sure how to access request parameters in JavaScript. I've tried a number of things, such as:



var jsAtt = ${myAtt};
var jsAtt = '${myAtt}';
var jsAtt = eval(${myAtt});
var jsAtt = eval('${myAtt}');


etc, but nothing seems to work.



Is there a way to grab request attributes via JavaScript? Please no jQuery, servlets, etc. I want pure JavaScript code.



I am kind of amazed I didn't find this already asked. So sorry if it is a duplicate and I just didn't see the orignal.


More From » jsp

 Answers
11

Using the following should work.



var jsAtt = '${myAtt}';


I think I stumbled across issues because of trying to dynamically generate the string based off my needs, which JavaScript seems to not like. For example, this would have issues:



var counter = 1;
var jsAtt = '${myAtt' + counter + '}';


JavaScript seems to recognize the request parameter syntax, but only if it's completely predetermined.


[#89389] Thursday, October 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yamileth

Total Points: 53
Total Questions: 96
Total Answers: 112

Location: England
Member since Tue, Sep 8, 2020
4 Years ago
;