Tomcat and JSP: Unable to compile class, cannot resolve to a type

T

tfrawley

I have installed Tomcat 6.0.18 and JDK 6u10.

The tomcat server works fine except when I attempt to use a class
file.

The physical path to the test site is: C:\Tomcat6\webapps\test

I placed a file named "index.jsp" in the above site with the following
contents:

<%@ page language="java"%>

<%
test.Hello h = new Hello();
h.run();
%>


I used javac to compile the following class (javac -d Hello.java):

package test;
public class Hello{
public void run(){
System.out.println("Hello World");
}}


and placed the class file in: C:\Tomcat6\webapps\test\WEB-INF\classes

When I open the site I get:

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

An error occurred at line: 4 in the jsp file: /index.jsp
test.Hello cannot be resolved to a type
1: <%@ page language="java"%>
2:
3: <%
4: test.Hello h = new Hello();
5: h.run();
6: %>
7:


An error occurred at line: 4 in the jsp file: /index.jsp
Hello cannot be resolved to a type
1: <%@ page language="java"%>
2:
3: <%
4: test.Hello h = new Hello();
5: h.run();
6: %>
7:


This seems so simple but it refuses to work. What am I doing wrong!?!?
 
A

Arne Vajhøj

I have installed Tomcat 6.0.18 and JDK 6u10.

The tomcat server works fine except when I attempt to use a class
file.

The physical path to the test site is: C:\Tomcat6\webapps\test

I placed a file named "index.jsp" in the above site with the following
contents:

<%@ page language="java"%>

<%
test.Hello h = new Hello();
h.run();
%>

I used javac to compile the following class (javac -d Hello.java):

package test;
public class Hello{
public void run(){
System.out.println("Hello World");
}}

and placed the class file in: C:\Tomcat6\webapps\test\WEB-INF\classes

When I open the site I get:

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

An error occurred at line: 4 in the jsp file: /index.jsp
test.Hello cannot be resolved to a type
1: <%@ page language="java"%>
2:
3: <%
4: test.Hello h = new Hello();
5: h.run();
6: %>
7:


An error occurred at line: 4 in the jsp file: /index.jsp
Hello cannot be resolved to a type
1: <%@ page language="java"%>
2:
3: <%
4: test.Hello h = new Hello();
5: h.run();
6: %>
7:

This seems so simple but it refuses to work. What am I doing wrong!?!?

The second error is because you need:

test.Hello h = new test.Hello();

The first error is because the class file should be in:
C:\Tomcat6\webapps\test\WEB-INF\classes\test

Fix both and you should run.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top