• 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

expressions in JSP

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1)

<HTML>
<HEAD><TITLE>FIRST JSP</TITLE></HEAD>
<BODY>
CURRENT TIME IS <%= new java.util.Date() %> // THIS IS COMMENT
</BODY>
</HTML>

In this code, out put will be CURRENT TIME IS ............


2)

<HTML>
<HEAD><TITLE>SECOND JSP</TITLE></HEAD>
<BODY>
<%= out.println("CURRENT TIME IS " + new java.util.Date()) %> //COMMENT
</BODY>
</HTML>

THIS CODE SHOULD PRODUCE SAME RESULT LIKE 1ST CODE, BUT IT GIVES ERROR. CAN ANYONE LET ME KNOW WHATS WRONG PLEASE ? I THINK IT DID WORK ONCE ON MY COMPUTER, BUT THEN IT IS THROWING EXCEPTION. CAN I NOT USE JAVA CODE IN EXPRESSION ? IF I PUT COMMENT IN THE CODE, SHALL IT BE PRINTED OR NOT ?

THANKS,
JIGNESH
[ February 20, 2008: Message edited by: jignesh soni ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
jignesh soni,
Typing with the caps-lock button down is the equivalent to yelling in a web forum and is considered to be rude. Many people won't even bother to read a question that is typed like this.

You can fix this problem by clicking on the icon in the top post of this thread.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please keep it down.

If you consider that what's inside a JSP expression is evaluated, coerced to a String and sent to the output, can you imagine what happens when you use out.println inside an expression ? Maybe you wanted to use sciptlets instead :
 
jignesh soni
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for reply.
If I use scriptlets, its working. I was thinking, why does it not work when I use expression and put out. println in the expression ?
Can anyone please explain ?

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JSP expression tags perform the "out.print" part for you.

So you would either use:
<%= YOUR_EXPRESSION %>
or
<% out.print( YOUR_EXPRESSION ); %>
 
This parrot is no more. It has ceased to be. Now it's a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic