File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "JSP Expression question" Watch "JSP Expression question" New topic

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("") %>

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

Deepak Bala

Joined: Feb 24, 2006
Posts: 6662

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

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:
subject: JSP Expression question
It's not a secret anymore!