aspose file tools*
The moose likes JSP and the fly likes print in JSP method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "print in JSP method" Watch "print in JSP method" New topic
Author

print in JSP method

Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
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

Joined: Dec 01, 2003
Posts: 106
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.


Hans Bergsten, hans@gefionsoftware.com<br />Author of O'Reilly's<br />- JavaServer Pages,<br />- JavaServer Faces<br /><a href="http://www.hansbergsten.com/" target="_blank" rel="nofollow">http://www.hansbergsten.com/</a>
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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.


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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 ]

Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Anand Gondhiya
Ranch Hand

Joined: Feb 24, 2004
Posts: 155
Thanks all.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: print in JSP method