File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Expression have nested Expression in a JSP page?

 
Sandesh Tathare
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I just tried following code:
----------------------------- index.jsp -----------------------------
<%@ page language="java"%>
<%!
private String getFormatedName(String name){
return name.toUpperCase();
}
%>
Author: <%= getFormatedName( <%= "test" %> )%> </br>
----------------------------- index.jsp -----------------------------
Note: I am trying to use expression to pass an argument to a method getFormatedName(String), which in turn is used in an expression.
On Tomcat I am getting following error:
A Servlet Exception Has Occurred
org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.
..\work\localhost\_\_0002findex_0002ejspindex_jsp_17.java:63: Missing term.
out.print( getFormatedName( <%= "test" );
^
..\work\localhost\_\_0002findex_0002ejspindex_jsp_17.java:63: Missing term.
out.print( getFormatedName( <%= "test" );
^
..\work\localhost\_\_0002findex_0002ejspindex_jsp_17.java:63: ')' expected.
out.print( getFormatedName( <%= "test" );
^
3 errors, 1 warning
Does that mean we can not use nested Expression in expression in JSP page?
Please reply ASAP.
Sandesh
 
Praful Thakare
Ranch Hand
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sandesh,
why do you want
Author: <%= getFormatedName( <%= "test" %> )%> ???
writing
Author: <%= getFormatedName( "test" )%> will give you the desired output.
Does that mean we can not use nested Expression in expression in JSP page?
Ofcourse it means the same,An expression is converted into out.println,
rather any sequence of characters written in <%=" asdfasdf "%>is converted as out.println(" asdfasdf ");.
so obviously if you write <%= getFormatedName( <%= "test" %> )%>
it will be converted to
out.println(getFormatedName( <%= "test" %> );
And no java compiler can digest it !!!
Cheers
Praful
 
Sandesh Tathare
Ranch Hand
Posts: 82
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Praful thanks buddy,
I was just trying out different combinations. And it really does not make sense when I am putting an expression as an argument to a method call that is in inside an expression.
I got u r point. Summing up. Value of expression will be printed to output stream of response. If at all I want value of a java variable to be passed as argument to a method call in expression, I need not use expression for it. Expression is not meant for it. Right?
Thanks any ways...
Sandesh
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic