0

Possible Duplicate:
How to use scriptlet inside javascript

<%
if(request.getAttribute("exception")!=null){%>

<script type="text/javascript" >
    alert("hi");

    parent.error.document.open();
    parent.error.document.write("bye");
    parent.error.document.write(<%=request.getAttribute("exception").toString()%>);
    parent.error.document.close();

</script>
</form>




<%}%>

Is it possible to have this sort of code? Is there any alternative?

Community
  • 1
  • 1
abson
  • 9,148
  • 17
  • 50
  • 69

2 Answers2

0

You're just missing some quotes to treat the value as a string, instead of a variable.

parent.error.document.write("<%=request.getAttribute("exception").toString()%>");

When printed to the page, it will appear as follows:

parent.error.document.write("myException");
Beau Grantham
  • 3,435
  • 5
  • 33
  • 43
0

Your code should work. But I prefer JSTL:

<c:if test="${not empty(exception)}">
    <script type="text/javascript">
        alert("hi");
        parent.error.document.open();
        parent.error.document.write("bye");
        parent.error.document.write(<%=request.getAttribute("exception").toString()%>);
        parent.error.document.close();

    </script>
</c:if>

Look more natural for jsp.

alexey28
  • 5,170
  • 1
  • 20
  • 25