• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling functions in JSp

 
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Can anybody tell me how to call functions in JSP's.
Pl reply with an example
Thanx in advance
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I assume you mean calling a bean function vs just having some Java code in your JSP or using a custom tag. I think it looks something like this:
Let the JSP know about the bean:
<jsp::useBean id="hello" class="com.blah.blah.HelloBean"/>
If you had a get (or a set) function like getName:
<jsp:getProperty name="hello" property="name"/>
Or you can do something that looks a little more like traditional Java:
<%@ page import="javax.servlet.jsp.JspFactory" %>
<% JspFactory factory = JspFactory.getDefaultFactory(); %>
These examples are from Web Development with JavaServer Pages by Fields & Kolb.
John
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi John,
I want to call a java function which will be used repeatedly in a particular JSP
For ex-
Lemme say that I want to add 2 numbers. For that I want to write a function as I don't want to repat my code again and again is say add.jsp
How do you write a function and call it multiple times in a single JSP( don't mistake it for beans function).
Hope you got my point
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can define a function say add in a declaration in a .jsp file as follows :
<%! public int add (int a, int b) {}<br /> %>
And then call this function wherever you require in a scriplet / expression as :
<%= add (5,6) %>
Having a function called add.jsp is confusing ...
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can define a function say add in a declaration in a .jsp file as follows :
<%! public int add (int a, int b) {}<br /> %>
And then call this function wherever you require in a scriplet / expression as :
<%= add (5,6) %>
Having a function called add.jsp is confusing ...
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You can define a function say add in a declaration in a .jsp file as follows

And then call this function wherever you require in a scriplet / expression as

Having a function called add.jsp is confusing ...
 
Madhu Juneja
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Click on the reply hyper link. The code is displayed
 
Mary Cole
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Thanx a lot
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if the function returns and object:
ConnectionClass getConnectio()
{
ConnectionClass conn = new ConnectionClass();
// the open connection code here;
return conn;
}
Later in the JSP page can I create a connection object and assign it the value returned from getConnection().
Thanks for your help;
 
Sheriff
Posts: 440
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm moving this to our "Servlets/JSP" forum where it is more appropriate.
Matt
[This message has been edited by Matt Midcap (edited June 29, 2001).]
 
ismail ismail
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Matt, I thought I am in the "Servlets and JSP's" forum, I am confused now!!
Please clear up my confusion..Thanks,
iismail

Originally posted by Matt Midcap:
I'm moving this to our "Servlets/JSP" forum where it is more appropriate.
Matt
[This message has been edited by Matt Midcap (edited June 29, 2001).]



[This message has been edited by ismail ismail (edited June 29, 2001).]
 
Oh the stink of it! Smell my tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic