• Post Reply Bookmark Topic Watch Topic
  • New Topic

expressions in JSP  RSS feed

 
jignesh soni
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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: 150
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 ); %>
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!