Running JSP on Linux tomcat

hello,

I have tomcat running on Linux. The test pages and the JSP examples that came with tomcat itself is running fine. However, when I want to make my own JSP files, they won't run.

I modified the webapps/jsp-examples/WEB-INF/web.xml file and added the new JSP files information, but it still won't run. Is there any other file that we have to add/modify information?

In fact, the new file is very similar to one of those sample JSP files, but still my JSP file is not working.. Besides, the new JSP file uses a Bean which is under webapps/jsp-examples/WEB-INF/classes/num (num is the package used) and its file permissions are set correct. The error message I am getting looks like this:

Apache Tomcat/5.0 - Error report

HTTP Status 500

Exception report

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

exception

javax.servlet.ServletException: Wrapper cannot find servletclass org.apache.jsp.num.tombic_jsp or aclass it depends on

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)

org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

java.lang.Thread.run(Thread.java:595)

root cause

java.lang.ClassNotFoundException: org.apache.jsp.num.tombic_jsp

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)

org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)

org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)

org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)

org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)

org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)

org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)

org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)

org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

java.lang.Thread.run(Thread.java:595)

[2746 byte] By [milhana] at [2007-11-27 4:48:22]
# 1

OK, I sort of figured out where the problem is, but I don't know how to fix it.

the above error is being generated because tomcat can't find the tombic_jsp.class file under /WEB-INF/classes/org/apache/jsp/num

but how do we generate this tombic_jsp.class class file? how do we compile a jsp file?

any help?

milhana at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

You can pre-compile jsp but it's not needed. Just make certain you packaged the jsp in a .war file which is accessed at the correct context. You can deploy jsp to a context you name e.g. localhost:8080/mycontext/myjsp.jsp or to the root context localhost:8080/myjsp.jsp. In the first case you archive the jsp in a .war file and in the latter case you copy your jsp to the ROOT.war directory.

Niklasa at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

thanks for your reply. how do we package the jsp file in a .war? and where do we place the .war file? I have a ROOT directory but no ROOT.war

> You can pre-compile jsp but it's not needed. Just

> make certain you packaged the jsp in a .war file

> which is accessed at the correct context. You can

> deploy jsp to a context you name e.g.

> localhost:8080/mycontext/myjsp.jsp or to the root

> context localhost:8080/myjsp.jsp. In the first case

> you archive the jsp in a .war file and in the latter

> case you copy your jsp to the ROOT.war directory.

milhana at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

The .war file can be packaged by your IDE or with ant. It's a zip file with the jsp, class files and XML. You then place the .war in the webapps directory. Alternatively for root context deployment, placing jsp in your ROOT directory should make it accessible from the root directory of localhost. On my jboss installation this directory for exploded deployment is called ROOT.war but on tomcat it's called ROOT. I recommend building your project with netbeans and then you can just copy the generated .war file from the dist directory to any java app servers deploy directory.

Niklasa at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

all right Niklas, let's go with the ROOT directory alternative. becasue in the mean time I tried the ROOT directory option and I made progress. at least this time it's generating the .java file, but then can't compile that .java file, giving a wierd error.

what I did is, I just moved my .jsp file under ROOT/ and SampleBean.class under ROOT/WEB-INF/classes/. And when trying to run the .jsp file from browser it gave me error saying it can't compile the _jsp.java.. here's what the error looks like:

org.apache.jasper.JasperException: Unable to compile class for JSP

Generated servlet error:

/srv/www/tomcat5/base/work/Catalina/localhost/_/org/apache/jsp/sample_jsp.java:6: '.' expected

import SampleBean;

^

1 error

> The .war file can be packaged by your IDE or with

> ant. It's a zip file with the jsp, class files and

> XML. You then place the .war in the webapps

> directory. Alternatively for root context deployment,

> placing jsp in your ROOT directory should make it

> accessible from the root directory of localhost. On

> my jboss installation this directory for exploded

> deployment is called ROOT.war but on tomcat it's

> called ROOT. I recommend building your project with

> netbeans and then you can just copy the generated

> .war file from the dist directory to any java app

> servers deploy directory.

By the way, do I still have to make any change in the ROOT/WEB-INF/web.xml file?

milhana at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Put your bean class in a package

package test;

import...........

and put the .class file in web-inf/classes/test/SampleBean.class, then specify the fully qualified name of the class in the useBean declaration

<jsp:useBean class="test.SampleBean" .../>

It will work. No XML necessary.

Niklasa at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
thanks a lot for your help Niklas, i finally got it working. : )
milhana at 2007-7-12 10:01:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...