> When I attempt to access methods defined in Java from a .JSP, > I am receiving > a message that the method is not being found. For example, I > have been > testing with the following .JSP: > > <%@page import="java.util.*, java.lang.*"%> > <% > // Test > > String myString = "100" ; > int myInt = parseInt(myString) ; > out.println("myInt is " + myInt) ; > > %> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> > <html> > <head> > <title>Simple Test of JAVA Classes</title> > <body> > </body> > </html> > > When I run this .JSP under Tomcat 3.2, I am receiving the > following message: > > Error: 500 > Location: /testapps/javaTest.jsp > Internal Servlet Error: > > org.apache.jasper.JasperException: Unable to compile class for > JSP/usr/tomcat/work/localhost_8080%2Ftestapps/_0002fjavaTest_0 > 002ejspjavaTes > t_jsp_0.java:65: Method parseInt(java.lang.String) not found in class > _0002fjavaTest_0002ejspjavaTest_jsp_0. > int myInt = parseInt(myString) ; > ^
You can't simply say parseInt("1.00"); you have to let the compiler know what instance, or in this case static instance, you want to call the method on. The reason for this is this method may be defined in several different class and the compiler won't know which to use. What the compiler is actually telling you is it looked for a method with the signature int parseInt(String s) defined in the current class(the JSP). Therefore, use the following, Integer.parseInt("1.00") This notifies the compiler to use the parseInt method in the Integer class. Also, just as a note, the import of java.lang.* is unnecessary. This is an implicit import. I would suggest getting a good java book and reading up on the basics of java before diving head first into servlets, jsp, and Tomcat. This is a very core theory in java and it doesn't seem like to fully understand the core theories of java yet. --- Michael Wentzel Software Developer Software As We Think - http://www.aswethink.com -- To unsubscribe: <mailto:[EMAIL PROTECTED]> For additional commands: <mailto:[EMAIL PROTECTED]> Troubles with the list: <mailto:[EMAIL PROTECTED]>