• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

is it a valid JSP expression

 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%= -2%>
Is it a valid JSP expression??
Thanks,
Trupti
 
Kamal Kishore
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes ! This is similar to
<%out.println(-2);%>
Kamal
 
trupti nigam
Ranch Hand
Posts: 627
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the mock exam question from the jweb+.
They have given this as the wrong answer.
The other correct answers are
<%= 2+3%>
<%= "2"+"3"%>
Thanks,
Trupti
 
Parag K
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I couldnt understand why this should be wrong. The JSP Specification clearly states that the Expression is converted to the java statement. (JSP.6.4.3), stated here for ready reference,
------------------------------------------------
JSP.6.4.3 Expressions
An expression is transformed into a Java statement to insert the value of the expression, converted to java.lang.String if needed, into the stream curnamed by the implicit variable out. No additional newlines or space is included.
Ignoring quotation and performance issues, this corresponds to a statement of the form:
Original Equivalent Text
-------------------------------------------------
<%= expression %> out.print(expression)
 
Maha Annadurai
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Made a test with a test.jsp having following code with Tomcat 4.0 and I did get -2 pinted out.
<html><body>
Value is <%= -2 %>
</body></html>
Regards,
Maha Anna
[ November 24, 2002: Message edited by: Maha Annadurai ]
 
Timber Lee
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
option is <% = -2 %> , instead of <%= -2 %>,
so it is wrong expression. does the real exam. have this kind of questions? I hope not!
 
R K Singh
Ranch Hand
Posts: 5384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid, but this kind of questions do come in real exam.
Do pay attention to minor details like 'blank', syntactically its wrong.
 
Zhiyong Sun
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tested both of them with Tomcat4.12 and both of them works fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic