This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to add a method to a jsp page?

 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
James Hodgkiss
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Short version:



You really need to work through a JSP tutorial before going much further.
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic