classpath issue? symbol not found.
Hello,
I'm very new to JSP and have seen lots of threads that implicate receiving a symbol not found error is due to the classpath not being configured properly.
I am trying to write a jsp that opens an http connection and sends a file from the local drive. The program works wonderfully as a standalone java app and I am currently trying to insert the code into a jsp. I am using a simply copy command to send the file stream to the http connection when I receive the following error:
...
Generated servlet error:
...60:Cannot find symbol
symbol: method copy(java.io.FileInputStream,java.io.ByteArrayOutputSteram)
location: class org.apache.jsp.index_jsp
copy(fin,bout);
I've added j2ee.jar, tools.jar, jsp.jar, servlet-api.jar, jsp-api.jar, . and all of the directories their in to my CLASSPATH, PATH, and as files/folders as libraries in my project. Nothing seems to work.
Can anybody please help? Thank you!
[982 byte] By [
balfortha] at [2007-11-26 22:27:46]

# 1
JSPs and Web applications in general are different from Desktop based apps.
You need to configure a Web app correctly from scratch, otherwise you may encounter problems during later stages and not know why something doesn't work.
Since you haven't provided additional relevant information, I must ask
1) Have you configured JAVA_HOME system environment variable to JDK's home folder ?
2) Have you installed a Web Server like Tomcat ? and configured it in the system environment? (for Tomcat you need to set CATALINA_HOME to Tomcat's home folder) - if you are using a different web server then check with the docs for that web server.
3) Can you post more relevant code of the error , and also post the full stack trace of the error you are getting. It's hard to tell what might be wrong with just the code you've provided. Please use the code button on top - it highlights your code's syntax and makes it easy on the eyes.
4) Lastly JSPs are best suited for the View , if you know (Model-View-Controller) , JSPs are best suited for displaying information.
Although it is possible to write Java code in the form of Scriptlets in JSPs it is highly discouraged as it leads to very messy and unmangeable code.
In a web app, one would normally write File I/O and such in Java Classes in the application layer, and not directly in JSP files. Then either use Servlets or JavaBeans to interact with the application layer from the JSP pages.
# 2
Hello and thank you for your reply! I apologize for being vague. This is all running on a standalone network so unfortunately I can't copy and paste, but I'll do my best to retype what I can.
In short, I am trying to write a web app that accepts coordinates passed to it through the URL from Google Earth, and then sends a SOAP message to a web service interface with those coordinates to retrieve information.
I started by utilizing SOAPClient4XG (http://www-128.ibm.com/developerworks/xml/library/x-soapcl/listing1.html) and have made almost no changes to the code. This reads XML (the SOAP message) from a file and sends it via an HttpURLConnection. This works great as a standalone Java app, however for it to work with Google Earth, it needs to be a URL/web link. I was just transfering the code from my .java file to my jsp file line by line inbetween <% %> tags. I will additionally need to write some code to parse the response and produce KML (Google's markup language), so that the JSP returns something pretty for Google to display.
In response to your questions:
1) My JAVA_HOME environment variable is set to "C:\Sun\SDK\jdk"
2) Tomcat is installed, and I do not have an environment variable set for CATALINA_HOME. I quickly tried to set it to "C:\Program Files\Apache Software Foundation\Tomcat 5.5" and tried again, but still received the same error.
3) Here is the full error:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occured at line: 18 in the jsp file: /index.jsp
Generated servlet error:
C:\Documents and Settings\me\.jstudio\Ent81\jakarta-tomcat-5.5.9_base\work\Catalina\localhost\SOAPJSP\org\apache\jsp\index_jsp.java:70: cannot find symbol
symbol : method copy(java.io.FileInputStream,java.io.ByteArrayOutputStream)
location: class org.apache.jsp.index_jsp
copy(fin,bout);
^
1 error
org.apache.jasper.compiler.DefaultErrorHAndler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.AntCompiler.generateClass(AntCompiler.java:246)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:288)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServletserviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
If it is harder to try to translate the above Java app to JSP, is there an easier way to send an XML message to another URL with JSP? I could probably write this in PHP in 5 minutes, but my boss is insisting that all future programs be written in Java.
Thank you for your quick response! If you need any further information, please do not hesitate to ask!
Message was edited by:
balforth
# 3
>
> 1) My JAVA_HOME environment variable is set to
> "C:\Sun\SDK\jdk"
This is fine
>
> 2) Tomcat is installed, and I do not have an
> environment variable set for CATALINA_HOME. I
> quickly tried to set it to "C:\Program Files\Apache
> Software Foundation\Tomcat 5.5" and tried again, but
> still received the same error.
It is better to install Tomcat on a path that has no spaces in
it. This may not be a problem at the moment, but but generally
helps avoiding future problems.
After setting CATALINA_HOME , you could add Tomcat's bin folder
to the PATH variable as %CATALINA_HOME%\bin; this way you can
type startup.bat and shutdown.bat anywhere on the command line, to start and stop tomcat.
>
> 3) Here is the full error:
> [code]org.apache.jasper.JasperException: Unable to
> compile class for JSP
>
> An error occured at line: 18 in the jsp file:
> /index.jsp
> Generated servlet error:
> C:\Documents and
> Settings\me\.jstudio\Ent81\jakarta-tomcat-5.5.9_base\w
> ork\Catalina\localhost\SOAPJSP\org\apache\jsp\index_js
> p.java:70: cannot find symbol
> symbol : method
> copy(java.io.FileInputStream,java.io.ByteArrayOutputSt
> ream)
> location: class org.apache.jsp.index_jsp
>copy(fin,bout);
> ^
> 1 error
>
The error is complaining that it is unable to find a method named "copy"
are you using that method anywhere in the code?
JSP syntax is a bit different from Java file syntax , not everything fits inside the scriptlet tags.
For example you can't have the package statement inside the scriptlet tag and you can't have import statements.
To import other classes you would use
<%@ page import="java.util.*, java.lang.*" %> syntax , details of the syntax are here: http://java.sun.com/products/jsp/syntax/2.0/syntaxref2010.html#15653
> If it is harder to try to translate the above Java
> app to JSP,
If you are familiar with the MVC design pattern, then it's not hard to translate the app into a JSP app.
In MVC one would write JSPs only to display information, and they would write Java Classes for the main application logic and they would use either JavaBeans or Servlets to interact between JSPs and the Application layer.
> is there an easier way to send an XML
> message to another URL with JSP? I could probably
In MVC one wouldn't use JSPs to send an XML message, you could use Java Classes in the application layer to send an XML too.
There are plenty of Java APIs available for this , there are APIs to generate XML , to send XML etc.
Are you imlementing some kind of a WebService? If you are then
Apache Axis (Java Based) might have methods in the API to make it easier to send / receive SOAP based messages.
http://ws.apache.org/axis/ , I don't know if you are using SOAP or REST , here's one on REST http://gomba.sourceforge.net/
> write this in PHP in 5 minutes, but my boss is
> insisting that all future programs be written in
> Java.
That's probably because beginners to any new language take a while
:-)
Then why didn't you pick a PHP job instead of a Java job?
Anyway, a robust way to write Java Web applications for businesses is to make use of the MVC design pattern.
JSPs View written with JSTL 1.1.x - avoid scriptlets
Java Classes , JavaBeans Model --
JDBC , DAO Classes Data access layer (you probably dont have this, for this app)
Java Servlets -- Controller to route JSPs
# 4
So what you're telling me is that I need to know what I'm doing before I try to do it? :) I do see what you're saying and completely agree. I will be spending more time going over the MVC design pattern.
I finally solved my problem and I feel like a complete idiot. It seemed to me that the copy method was some sort of standard Java method and it looked like there was tons of documentation on the internet supporting a copy method. I was just posting the code in this reply when I saw that the copy method was defined at the bottom of the original Java app!!!
So I stuck the whole copy method between <%! %> tags, and the main code between <% %> tags, and it works!
Thank you very much for taking the time to respond to me! I promise I will learn the MVC method and not write crappy code in the future! :)
# 5
You're welcome.
I have no clue what you did to solve your problem :-) , but it's ok, for now.
Scriptlets <% %> , Declarations <%! %> and Expressions <%=%> were used in the early days of JSP.
And back then it was known as Model 1 archtecture when everything (UI, business and database logice) was written in JSPs.
Now one writes JSPs with JSTL 1.1 tags - the functionality of these tags is limited so that they are used only to *display* information, which then forces the programmer to write application logic in the middle tier.
If you are new to JSPs it helps to get familiar with JSP basics and then move to JSTL.
JSPs also have a tag called jsp:useBean which is used to access a JavaBean.
I guess this information is enough to get you started on the right track.