• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Expression have nested Expression in a JSP page?

 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 645
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic