Your question leaves out several significant facts, but I'll make some
assumptions:
1. All of the code snippets shown actually appear in a jsp rather than mixed
with a servlet.
2. The code snippets appear in the exact order shown
3. The snippets appear in a code fragment server tag (ie, <% and %>)
Given those assumptions:
1. The method declaration should appear in a declaration tag (ie, %<! and
%>)
Try coding as below.
<%!
public String validateStr(int length,String str)
{
if(str!=null)
{
if(str.length()>length)
{
System.out.println("Wrong Entry"+str);
return "0";
}
else return str;
}
else
return "0";
}
%>
<%
int retValue=
custQuery.insertCustomer(intCustId,validateStr(30,firstname),validateStr
(30,lastname),validateStr(8,sex),validateStr(10,age),validateStr(30,inco
me),validateStr(30,profession),validateStr(30,education),validateStr(10,
familysize),validateStr(2,country),validateStr(50,company),validateStr(5
0,jobtitle),validateStr(80,officemailaddress),validateStr(50,officemaila
ddress1),validateStr(30,officecity),validateStr(30,officestate),validate
Str(20,officeZip),validateStr(10,officeAreacode),validateStr(20,officeph
oneno),validateStr(20,officefax),validateStr(80,officeEmailaddress),vali
dateStr(80,Homemailaddress),validateStr(50,Homemailaddress1),validateStr
(30,Homecity),validateStr(30,Homestate),validateStr(20,HomeZip),validate
Str(10,HomeAreacode),validateStr(20,Homephoneno),validateStr(20,Homefax)
,validateStr(80,HomeEmailaddress),validateStr(80,personalhomepage),valid
ateStr(4,noofvisits),validateStr(32,lastvisit),validateStr(50,ipaddress)
,validateStr(50,browser),dateofregistration,emailsent,validateStr(1,inactiva
te),validateStr(1,load),dateloaded,validateStr(10,b
irthyear));
%>
I realize the intuitive approach indicates method "code" should appear in a
code tag; but, in reality the method definition is a declaration and must
appear in a declaration tag, while its invocation must appear in a code tag.
-----Original Message-----
From: satya b
To: [EMAIL PROTECTED]
Sent: 2/29/00 10:31 PM
Subject: How to call a method in JSP !!!!
Hi gueys,
I am converting servlets to jsp.Actually in servlets
we will define class and methods.In case of JSP we
won't define classes,in that case how to call a method
in JSP. I got the error msg as ......
c:\j2sdkee1.2\repository\RICH-S\web\ganrt\_0005cRegister_0002ejspRegiste
r_jsp_0.java:390:
Statement expected.
public String validateStr(int
length,String str)
^
c:\j2sdkee1.2\repository\RICH-S\web\ganrt\_0005cRegister_0002ejspRegiste
r_jsp_0.java:404:
Class or interface declaration expected.
}catch (Exception ex) {
My code is like this:
-----------------------
int retValue=
custQuery.insertCustomer(intCustId,validateStr(30,firstname),validateStr
(30,lastname),validateStr(8,sex),validateStr(10,age),validateStr(30,inco
me),validateStr(30,profession),validateStr(30,education),validateStr(10,
familysize),validateStr(2,country),validateStr(50,company),validateStr(5
0,jobtitle),validateStr(80,officemailaddress),validateStr(50,officemaila
ddress1),validateStr(30,officecity),validateStr(30,officestate),validate
Str(20,officeZip),validateStr(10,officeAreacode),validateStr(20,officeph
oneno),validateStr(20,officefax),validateStr(80,officeEmailaddress),vali
dateStr(80,Homemailaddress),validateStr(50,Homemailaddress1),validateStr
(30,Homecity),validateStr(30,Homestate),validateStr(20,HomeZip),validate
Str(10,HomeAreacode),validateStr(20,Homephoneno),validateStr(20,Homefax)
,validateStr(80,HomeEmailaddress),validateStr(80,personalhomepage),valid
ateStr(4,noofvisits),validateStr(32,lastvisit),validateStr(50,ipaddress)
,validateStr(50,browser),dateofregistration,emailsent,v!
alidateStr(1,inactivate),validateStr(1,load),dateloaded,validateStr(10,b
irthyear));
public String validateStr(int length,String str)
{
if(str!=null)
{
if(str.length()>length)
{
System.out.println("Wrong Entry"+str);
return "0";
}
else return str;
}
else
return "0";
}
This method i had called so many times like this..But
it is giving error as....
So pls help me in this....
Waiting for your solution.....
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
========================================================================
===
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets