Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use jsp scriptlets in jspx files?

Tags:

java

jsp

jspx

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.

like image 583
zawhtut Avatar asked Nov 20 '10 10:11

zawhtut


2 Answers

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.

like image 157
BalusC Avatar answered Sep 30 '22 02:09

BalusC


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>
like image 26
Chanoch Avatar answered Sep 30 '22 04:09

Chanoch