• 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

is it a valid JSP expression

 
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<%= -2%>
Is it a valid JSP expression??
Thanks,
Trupti
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes ! This is similar to
<%out.println(-2);%>
Kamal
 
trupti nigam
Ranch Hand
Posts: 647
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tested both of them with Tomcat4.12 and both of them works fine.
 
reply
    Bookmark Topic Watch Topic
  • New Topic