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

How to add a method to a jsp page?

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
I've got this jsp code, and I want to add a method to it - how do I do it?!...


...do I HAVE to go the servlet route?

Cheers,
James
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Why add a method to the page? Why not factor any processing out into a bean that you can call. Adding code to a JSP is not just one, but two levels of conventional patterns and practices out of date.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
I'm new to JSP. Would you be able to give me a link where I can find an example of how to do that? Or can you provide an example?

Thanks,
James
[ November 01, 2007: Message edited by: James Hodgkiss ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Are you also new to Java? If not, just create a bean like any other that provides the method you need.

Using beans from a JSP will be covered in any JSP tutorial worth its salt.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
No, I'm not new to Java - I just don't know how to call a bean from jsp. I am new to jsp.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Short version:



You really need to work through a JSP tutorial before going much further.
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

if possible, dont declare any methods in jsp.
But if you must do it, you thn you can declare a method in declaration



<%! %> is called declaration


[Servlet tutorial] [Servlet 3.0 Cook Book]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61206
    
  66

Originally posted by sudhir nim:
<%! %> is called declaration


The use of declaration is not advised -- especially for those new to JSP. Delcarations are the easiest way to introduce thread-safety issues into a JSP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to add a method to a jsp page?