• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Expression question

 
reubin haz
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" %>
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abhilash Mutugudurmut
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic