wood burning stoves 2.0*
The moose likes JSP and the fly likes Can Expression have nested Expression in a JSP page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "Can Expression have nested Expression in a JSP page?" Watch "Can Expression have nested Expression in a JSP page?" New topic
Author

Can Expression have nested Expression in a JSP page?

Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82
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


Regards,<br />Sandesh<br />(SCJCP, SCWCD, SCBCD - 99%, OCP-1)<br /> <br />Either find a way or create one.
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 637
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


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Sandesh Tathare
Ranch Hand

Joined: Jun 22, 2003
Posts: 82

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
 
Don't get me started about those stupid light bulbs.
 
subject: Can Expression have nested Expression in a JSP page?