• Post Reply Bookmark Topic Watch Topic
  • New Topic

trouble calling a java imported class in a jsp page

 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have inported a package that i have created and have imported it into my jsp page. When i try and call the function normalize() in the class test i get this error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\treeapp\running_jsp.java:59: normalize() in mypackage.test cannot be applied to (java.lang.String,java.lang.String,java.lang.String)
[javac] test.normalize(user,pass,systemChoice);
It sounds like its saying that there is a fuction called normalize() with no parameters and that passing three strings to it won't work but the normalize function reads in three strings and my jsp page passes three strings.
Any help would be gratly appreciated
Thanks
Tex
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you included the java files in your class path?
Typically, I put my java classes used by my jsp's in:
c:\tomcat\webapps\<my app name>\WEB-INF\classes.
The package folder reside under "classes", so I add the above path to my classpath environment variable.
Next, I move my compiled java classes from my development folder to the appropriate package folder under "classes".
In your case, you would move Test.class into:
c:\tomcat\webapps\<my app name>\WEB-INF\classes\mypackage\
In your JSP, you need to import the class and call it with in scriptlet tags:

In Test.java, I'm assuming the normalize() method is defined as non-static and takes 3 strings as parameters:

Make sure that the type of parameters and the return type in normalize() match your code in your JSP.
-Graff
 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Graff,
<%-- java include files --%>
<%@ page import="java.io.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="java.util.*" %>
<%@ page import="mypackage.*" %>
<%
String user = request.getParameter("user");
String pass = request.getParameter("pass");
String systemChoice = request.getParameter("system");
test Test1 = new test();
test.normalize(user,pass,systemChoice);
%>
This is the code i have in my jsp page, The package is recognized because i used to get an error that it couldn't find it but i have added it to the C:\Program Files\Apache Group\Tomcat 4.1\shared\classes directory and the error saying that it couldn't find mypackage is gone.
I also have the direcotry in my class path variable. But i still get the same error.
Normalize is a public void function
public void normalize(String user, String pass, String systemChoice){
}
anything else that i could try??
Thanks
Tex
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

test Test1 = new test();
test.normalize(user,pass,systemChoice);


Hi,
I think you have some things backwards in your code. "test" with a lowercase "t" is the class here, not the instance. You are declaring an instance of class "test" named "Test1", so to call a method on that instance you would have to do the following:

Give that a shot.
E
 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried changing it to Test1.normalize(user,pass,systemChoice); and i still get the same error:
normalize() in mypackage.test cannot be applied to (java.lang.String,java.lang.String,java.lang.String)
Tex
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm, that's interesting. Can you post the source to your test class?
 
Tex Abrey
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The source for the test.class

package mypackage;
import java.io.*;
import java.util.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import oracle.xml.parser.v2.*;
import org.xml.sax.helpers.*;
import java.net.*;
import MyDocumentBuilder;

public class test
{
public test()
{
}
public void normalize(String user, String pass, String systemChoice) throws Exception
{
try {
SAXParser saxParser = new SAXParser();
MyDocumentBuilder docBuilder = new MyDocumentBuilder();
saxParser.setContentHandler(docBuilder);
saxParser.parse(fileNameToURL("C:/David/xml/test.xml"));
XMLDocument xdoc = docBuilder.getDocument();
PrintWriter out = new PrintWriter(new FileWriter("c:/David/xml/temp.xml"), true);
out.print("<?xml version='1.0' encoding='UTF-8'?>");
xdoc.print(out);
Document doc = parsing.parseXmlFile("c:/David/xml/temp.xml",false);
parsing.visit(doc, 0, user, pass, systemChoice);
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
public static URL fileNameToURL(String fileName) throws Exception
{
File file = new File(fileName);
String path = file.getAbsolutePath();
char fSep = file.separatorChar;
path = path.replace(fSep, '/');
if (path.length() > 0 && path.charAt(0) != '/')
path = '/' + path;
return new URL("file", null, path);
}

}

_______________________________________________
Tex
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be less confusing for everyone involved, including yourself in the long run, to follow the conventional Java naming of declaring classes with a capitalized name, and variables starting with lowercase.
That said, your call to test.normalize reference the class, not your instance. Since normalize is an instance method, no joy.
To call the method on your instance, you must use the instance variable. So:

should work just fine.
hth,
bear
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I don't see anything wrong with your code, so I'm thinking it is likely a classpath issue, though not an obvious one. Do you have an older or different version of the test class in your classpath somewhere, maybe a version with a normalize method with no args? I'm a little rusty on how Tomcat handles Class loading, so this is just a shot in the dark, but it sounds like it is not finding the right class to me.
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tex Abrey:
When i try and call the function normalize() in the class test i get this error:
C:\Program Files\Apache Group\Tomcat 4.1\work\Standalone\localhost\_\treeapp\running_jsp.java:59: normalize() in mypackage.test cannot be applied to (java.lang.String,java.lang.String,java.lang.String)
[javac] test.normalize(user,pass,systemChoice);

Thanks
Tex

I've found that although Windows accepts spaces in a classpath, Java does not like them. Perhaps having Tomcat installed in a directory without spaces in the path might help.
The other puzzling thing is that if the JVM couldn't find the method definition (or if it was incorrect, you would see an error message from the JVM like "could not resolve symbol".

Try renaming your class to adhere to the Java naming convention standards "Test.java" (capital 't').
It would also be helpful if you posted the exact stack trace that you are seeing.
-Graff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!