admin管理员组文章数量:1389783
I have a Java servlet which sets an attribute on the HttpServletRequest object:
request.setAttribute("SOME_STRING", somestring);
Now, in my page.jsp, I want to set this string to be displayed in an HTML textarea...
I've been trying to do something like this, but I just can't get it to display the string:
var somestr = <%= (String) (request.getAttribute("SOME_STRING")) %>;
document.getElementById("my_textarea").value = somestr;
The textbox now displays "[Object object]" instead of the string itself.
How can I get it to display the actual string?
I have a Java servlet which sets an attribute on the HttpServletRequest object:
request.setAttribute("SOME_STRING", somestring);
Now, in my page.jsp, I want to set this string to be displayed in an HTML textarea...
I've been trying to do something like this, but I just can't get it to display the string:
var somestr = <%= (String) (request.getAttribute("SOME_STRING")) %>;
document.getElementById("my_textarea").value = somestr;
The textbox now displays "[Object object]" instead of the string itself.
How can I get it to display the actual string?
Share Improve this question asked Dec 8, 2013 at 16:53 JoshJosh 7076 silver badges22 bronze badges 1-
What do you put at somestring at
request.setAttribute("SOME_STRING", somestring);
– Masudul Commented Dec 8, 2013 at 17:08
3 Answers
Reset to default 3Please change your line from
var somestr = <%= (String) (request.getAttribute("SOME_STRING")) %>;
to
var somestr = '<%= (String) (request.getAttribute("SOME_STRING")) %>';
Enclose var somestr
with single quotations ' '
,
var somestr = '<%= (String) (request.getAttribute("SOME_STRING")) %>';//Add ' '
document.getElementById("my_textarea").value = somestr;
<script type="text/javascript">
var attrib ="<%=request.getAttribute("hello") %>";
alert(attrib);
</script>
Enclose your scriptlet with quotes.
本文标签:
版权声明:本文标题:java - How to convert JSP request attribute to a string and assign it to an object in JavaScript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744741449a2622632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论