This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60785
    
  65

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: 60785
    
  65

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: 60785
    
  65

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: 60785
    
  65

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.
 
 
subject: How to add a method to a jsp page?
 
Similar Threads
Does anyone know what this error means?
Display XML/HTML file in TextArea in Web page
JSP EDITOR QUETION? NEED HELP
Help with posting data from servlet see code
JBoss - multiple vagueness