This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes JSP Expression question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Expression question" Watch "JSP Expression question" New topic
Author

JSP Expression question

reubin haz
Ranch Hand

Joined: May 12, 2005
Posts: 287
Can someone please tell me why the 1st one is incorrect and the 2nd one is correct? Thanks.

1. <%= System.out.println("j2eecertificate.com") %>

2. <%= "Variety is the spice of life" %>


SCJA, SCJP5.0, SCBCD, SCWCD
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The first one returns void. You cannot use something that returns void inside an expression. The second one is a String that is passed to the out.println() function (If memory serves me right). This is correct because the println() function is overridden to accept Strings.


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Abhilash Mutugudurmut
Greenhorn

Joined: Jul 03, 2006
Posts: 16
i think the answer to your problem is
expressions inside JSP when translated into servlet they go into
service method i.e between out.print(" ");
therefore out.print cannot expect another print statement inside it.
or it could be this
only print writer out is valid not System.out inside a jsp/a servlet.
 
 
subject: JSP Expression question
 
Similar Threads
Across JVM's
How to compute the count of html_tag each line?
? How to call JAXP/JDOM from other class
how to access combo-box value in javascript?
diff btw '&lt;!-...-&gt;' and '&lt;!--.. --&gt;'