Link to home
Start Free TrialLog in
Avatar of stefanaichholzer
stefanaichholzerFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Problems with JSP

I'm running Tomcat 5.0 and it all works fine, I'm mostly doing servlets and it's all cool. Now I would like to move to .jsp pages but I can't get the damn thing to work and I don't know why...

Do I have to create a new webapp for my .jsp files or add some xml info or what?

I have a simple example:

 <HTML>
 <BODY>
  Hello!  The time is now <%= new java.util.Date() %>
 </BODY>
 </HTML>

When I call it from my browser I get errors like this:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
      org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
      org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:106)
      org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:935)
      org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
      org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

Now, why am I getting this errors?, do I have to import something like a regular .java file or what?

Thank in advance and please provide some usefull tips...

;)
Avatar of petmagdy
petmagdy
Flag of Canada image

Yes make sure that u defined in ur Path Env. variable:

${Java_home}\bin

also that:
${Java_home}\lib\tools.jar

is in ur classpath
Avatar of stefanaichholzer

ASKER

How, where do I do that? I can't seem to find somthing to do that in Tomcat

Thanx
if ur JDK is installed for example at c:\jdk14.2 the
1- make sure that ur OS PATH enviroment variable part of it is ....;c:\jdk14\bin;.....

also open ur tomcat startup batch file and make sure that part of the classpath is c:\jdk14.2\lib\tools.jar
ASKER CERTIFIED SOLUTION
Avatar of kiranhk
kiranhk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You should be able to get by with <just> defining the JAVA_HOME environment variable to point to your local JDK installation.   The tomcat startup scripts will implicitly add %JAVA_HOME%/bin to the path where neccessary.

One easy way to do this is to open up startup.bat and define JAVA_HOME at the top of it (other apps may need different versions of the JDK).

kiranhk and friends,

OK, I added following lines to the startup.bat file:

  set JAVA_HOME=C:\Global\Java\jdk1.4\
  set CATALINA_HOME=C:\Global\Apache\Tomcat 5.0\

Reloaded the server and still the same errores, and I don't know how to add the tools.jar into the classpath.

Errors I get:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP
      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:97)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:346)
      org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:414)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK
      org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory.getCompiler(CompilerAdapterFactory.java:106)
      org.apache.tools.ant.taskdefs.Javac.compile(Javac.java:935)
      org.apache.tools.ant.taskdefs.Javac.execute(Javac.java:764)
      org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:382)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
How does the /jsp-examples/ folder run the .jsp files?, I went through the folder and there is some .xml defining all the .jsp files that are in the folder, do I have to do something like that?, because if I have to I give up JSP :(

Thanx
Avatar of kiranhk
kiranhk

No you dont have to put any xml file.
Maybe there is problem with the JAVA_HOME you would have set.
can you check out catalina.bat and see if this line exists

call "%CATALINA_HOME%\bin\setclasspath.bat"

and if it is there can you also check out in setclasspath.bat whether it is having this line

set CLASSPATH=%JAVA_HOME%\lib\tools.jar


Then make sure your your Java installation is correct.

If any of those line are not there can you add them and check
Ok, I guess that's it, I added the lines kirank gave me, but still the damn thing wasn't working. I was using the Tomcat monitor to restart the server and that was not doing it, then I started the server from the DOS prompt, using the startup.bat and then it worked just fine. I can now run all my .jsp files.

Still I would like to know why did I have to restart the server using the startup.bat and why wouldn't it work using the Tomcat monitor??

Thanx to all you guys...

 --> http://stefan.cuencaweb.com/thanx.htm