|
-
December 3rd, 2002, 01:10 PM
#1
Defining a stand-alone method/function?
I am learning Java (or more specifically, JSP) and am working on my final project for class. As part of the JSP page I am creating, I want to perform the same string concatenation on each field value to build the appropriate HTML. Normally (with other languages), I would define a function to do this. But I am having trouble getting the syntax right to make this work. Here is the code for my function declaration:
Code:
//Takes a string and builds an HTML value attribute out of it.
String FieldToValue(String str)
{
String retStr = "";
if (str.length() > 0) {
retStr = "value='" + str + "' ";
}
return retStr;
}
And here is the error I am receiving:
Code:
<path removed>/_0002fidev_00031_00031_00031final_0002fcustdetail_0002ejspcustdetail_jsp_0.java:63: ')' expected.
String FieldToValue(String str)
^
I've tried declaring the function with the public or private keywords, but then Tomcat complains that it wants a statement in their place.
Can I even do this? Or do I need to actually create a .class file (something I really don't have time to play with right now) just to establish a function for use?
- Shawn
MCP, VB6: Desktop Apps
[ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
Unless otherwise stated, all sample code provided is UNTESTED.
http://www.codemastershawn.com
-
December 3rd, 2002, 02:15 PM
#2
You can have a method (function) on a JSP page, but it must be within the declarations tags
Code:
<%! // note the !
String FieldToValue(String str)
{
String retStr = "";
if (str.length() > 0) {
retStr = "value='" + str + "' ";
}
return retStr;
}
%>
-
December 3rd, 2002, 03:47 PM
#3
Excellent! Thanks Goodz
- Shawn
MCP, VB6: Desktop Apps
[ C# | VB | .NET | Java | VC++ | Perl | PHP | Javascript ]
Unless otherwise stated, all sample code provided is UNTESTED.
http://www.codemastershawn.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|