File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 6662
    
    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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP Expression question