Forums Register Login

expressions in JSP

+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 :
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
JSP expression tags perform the "out.print" part for you.

So you would either use:
<%= YOUR_EXPRESSION %>
or
<% out.print( YOUR_EXPRESSION ); %>
Screaming fools! It's nothing more than a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 828 times.
Similar Threads
alert function
tomcat can't find index.jsp
Viewing JSP files
question from java black belt?
getParameter() in JSP always returns null...why?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 17:32:10.