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

User Defined Functions in JSP

Hari Haran
Greenhorn

Joined: Aug 23, 2003
Posts: 10
Hi ,
Can we make use of User Defined functions In JSP as we do in ASP ? If yes tell me the Syntax and how to call the function ?
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 639
Hari,
I dont have knowledg of ASP,but this is how u can define and call function in jsp
[B]<%![B]
public void myfunction()
{
}
%>
<%
myfunction();
%>
Hope this helps you
Cheers
Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
Hari Haran
Greenhorn

Joined: Aug 23, 2003
Posts: 10
Originally posted by Praful Thakare:
Hari,
I dont have knowledg of ASP,but this is how u can define and call function in jsp
[B]<%![B]
public void myfunction()
{
}
%>
<%
myfunction();
%>
Hope this helps you
Cheers
Praful


hi ,This is how i tried it . I had only this code in my jsp file .
<%!
public void myfunction()
{
%>
<%="inside function "%>
<%
}
%>
<%
myfunction();
%>

but it gives the following error:
Error: 500
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:\jakarta-tomcat-3.2.4\work\localhost_8080%2Fppfp\_0002fjsp_0002fWebSite_0002ftest_0002fTestFunction_0002ejspTestFunction_jsp_0.java:22: '}' expected.
{
^
C:\jakarta-tomcat-3.2.4\work\localhost_8080%2Fppfp\_0002fjsp_0002fWebSite_0002ftest_0002fTestFunction_0002ejspTestFunction_jsp_0.java:25: Statement expected.
static {
^
C:\jakarta-tomcat-3.2.4\work\localhost_8080%2Fppfp\_0002fjsp_0002fWebSite_0002ftest_0002fTestFunction_0002ejspTestFunction_jsp_0.java:76: 'try' without 'catch' or 'finally'.
out.write("\r\n");
^
C:\jakarta-tomcat-3.2.4\work\localhost_8080%2Fppfp\_0002fjsp_0002fWebSite_0002ftest_0002fTestFunction_0002ejspTestFunction_jsp_0.java:83: Type expected.
} catch (Exception ex) {
^
4 errors
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Welcome to the Ranch Hari!
You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it.
In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.
Thanks!
bear
JSP Forum Bartender
[ December 12, 2003: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

=====
<%!
public void myfunction()
{
%>
<%="inside function "%>
<%
}
%>
<%
myfunction();
%>
======
u can not mix both declaration & expressions & scriplets...see u did not complete ur declaration part,,but u include one expreassion...


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: User Defined Functions in JSP