Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

print in JSP method

 
Anand Gondhiya
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Quick question !
How do I print in JSP method.
for example:
<%! void method()
{
}
%>

how to put print out statements in this method ?
thanks in advance
-Anand.
 
Hans Bergsten
Author
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Anand Gondhiya:
Hi All,
Quick question !
How do I print in JSP method.
for example:
<%! void method()
{
}
%>

how to put print out statements in this method ?
thanks in advance
-Anand.

Do you mean print to the response? If so, I recommend that you don't do that; use template text and action elements (such as the JSTL <c ut> action) instead. Avoid Java code in the JSP pages; it just causes a lot of maintenance problems.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSTL is recommended because it can keep the JSP code clean.
If you want to print "This is a string", then you can use:

If you are new to JSTL and still want to print the statement out inside scriptlet, you can use the implicit variable out by:

put inside your method.
Nick.
 
Prakash Dwivedi
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anand,
Hans Bergsten & Nicholas Cheung are right,you should use tags instead.
Also you should avoid using such type of programming(creating methods in jsp page for computation), JSP should be used for presentation.
But if you want to do it, Here is how you can do it


[ March 11, 2004: Message edited by: Prakash Dwivedi ]
 
Anand Gondhiya
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic