7

Is there a way I can use the jsp scriptlets in jspx files ? Writing like this <%="hello"%> in jspx file gave me errors. Please help.

bjoernz
  • 3,852
  • 18
  • 30
zawhtut
  • 8,335
  • 5
  • 52
  • 76

2 Answers2

9

You can use <jsp:scriptlet> and <jsp:expression> for this. It has however to be wrapped in an ugly <[CDATA[ block.

Using scriptlets is discouraged anyway. I'd forget about it all and put Java code in Java classes.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
5

Just for my own sanity and record: (Oracle really don't make a good job of explaining this). Strictly for debugging: (spring's documentation is so detailed, I get lost)

You can use:

<jsp:scriptlet>
  <![CDATA[
    java.util.Enumeration e=request.getAttributeNames();
    while(e.hasMoreElements())
    {
      String name=(String)e.nextElement();
      out.print(name);
      out.print(":");
      Object value=request.getAttribute(name);
      out.print(value);
      out.print("<br/>");
    }
  ]]>
</jsp:scriptlet>
Chanoch
  • 563
  • 7
  • 16