Passing a servlet variable

Hi gurus,

I know this is a no-javascript forum, but this really is more of a JSP/servlet question. If I pass the following variable via a servlet:
request.setAttribute(“myString”, “HELLO”);

I can access the variable with the affected JSP by:
<%= (String) request.getAttribute(“myString”) %>

My Problem is this:
I have a very simple javascript embedded in the affected JSP as follows:

function runthis() {
var test = <%= (String) request.getAttribute(“myString”) %>;
alert(test);
}

This does NOT work when I call that function. Can I not access a servlet variable via javascript?

Thanks in advance…

you’re missing the quote.
var test = ‘<%= (String) request.getAttribute(“myString”) %>’;

you can also use shortform
var test = ‘${myString}’;

OH…MY…GOD…I cannot believe I’ve been pining over this for a month and the quotations were the only thing I was missing!! :mad:

Thank you!!! :slight_smile: