开发者

Can I use jsp scriptlets in jspx files?

开发者 https://www.devze.com 2023-01-26 05:40 出处:网络
Is there a way I can use the jsp scriptlets in j开发者_Go百科spx files ? Writing like this <%=\"hello\"%>in jspx file gave me errors. Please help.You can use <jsp:scriptlet> and <jsp:ex

Is there a way I can use the jsp scriptlets in j开发者_Go百科spx files ? Writing like this <%="hello"%> in jspx file gave me errors. Please help.


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.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消