• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

User Defined Functions in JSP

 
Hari Haran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Hari Haran
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64718
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Krishna Srinivasan
Ranch Hand
Posts: 1862
Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
=====
<%!
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic