Tomcat JSP importing class error

T

tfrawley

This has got to be an easy problem but we cannot seem to figure it
out.

I am using Tomcat 6.0.18 and JRE 1.5.09

This is my class:


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



This is my JSP:


<%@ page language="java" import="java.util.* , java.io.* ,
java.text.*" errorPage="error.jsp"%>
<%@ page import="hello.*" %>
<%
hello h = new hello();
h.run();
%>



and this is the error:

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

An error occurred at line: 7 in the jsp file: /test.jsp
hello cannot be resolved to a type
4:
5: <%
6:
7: hello h = new hello();
8: h.run();
9:
10: %>

I have the "hello.class" in

C:\Tomcat6\webapps\ROOT\WEB-INF\classes\hello
C:\Tomcat6\webapps\ROOT\WEB-INF\classes
C:\Tomcat6\webapps\ROOT\WEB-INF
C:\Tomcat6\webapps\manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\manager\WEB-INF\classes
C:\Tomcat6\webapps\manager\WEB-INF
C:\Tomcat6\webapps\host-manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\host-manager\WEB-INF\classes
C:\Tomcat6\webapps\host-manager\WEB-INF



Can someone pelase offer a suggestion and please tell me where the
CLASS file should actually reside? Please?
 
A

Arne Vajhøj

This has got to be an easy problem but we cannot seem to figure it
out.

I am using Tomcat 6.0.18 and JRE 1.5.09

This is my class:

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


This is my JSP:


<%@ page language="java" import="java.util.* , java.io.* ,
java.text.*" errorPage="error.jsp"%>
<%@ page import="hello.*" %>
<%
hello h = new hello();
h.run();
%>

and this is the error:

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

An error occurred at line: 7 in the jsp file: /test.jsp
hello cannot be resolved to a type
4:
5: <%
6:
7: hello h = new hello();
8: h.run();
9:
10: %>

I have the "hello.class" in

C:\Tomcat6\webapps\ROOT\WEB-INF\classes\hello
C:\Tomcat6\webapps\ROOT\WEB-INF\classes
C:\Tomcat6\webapps\ROOT\WEB-INF
C:\Tomcat6\webapps\manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\manager\WEB-INF\classes
C:\Tomcat6\webapps\manager\WEB-INF
C:\Tomcat6\webapps\host-manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\host-manager\WEB-INF\classes
C:\Tomcat6\webapps\host-manager\WEB-INF

Can someone pelase offer a suggestion and please tell me where the
CLASS file should actually reside? Please?

C:\Tomcat6\webapps\foobar\WEB-INF\classes\hello

if your JSP is in C:\Tomcat6\webapps\foobar

Arne

PS: Traditionally class names are capitalized.
 
M

Mark Space

C:\Tomcat6\webapps\ROOT\WEB-INF\classes\hello
Can someone pelase offer a suggestion and please tell me where the
CLASS file should actually reside? Please?

This looks like a directory listing... why is "hello" not named
"hello.class"?
 
N

Nostalgia

This has got to be an easy problem but we cannot seem to figure it
out.

I am using Tomcat 6.0.18 and JRE 1.5.09

This is my class:

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

}}

This is my JSP:

<%@ page language="java" import="java.util.* , java.io.* ,
java.text.*" errorPage="error.jsp"%>
<%@ page import="hello.*" %>
<%
hello h = new hello();
h.run();
%>

and this is the error:

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

An error occurred at line: 7 in the jsp file: /test.jsp
hello cannot be resolved to a type
4:
5: <%
6:
7: hello h = new hello();
8: h.run();
9:
10: %>

I have the "hello.class" in

C:\Tomcat6\webapps\ROOT\WEB-INF\classes\hello
C:\Tomcat6\webapps\ROOT\WEB-INF\classes
C:\Tomcat6\webapps\ROOT\WEB-INF
C:\Tomcat6\webapps\manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\manager\WEB-INF\classes
C:\Tomcat6\webapps\manager\WEB-INF
C:\Tomcat6\webapps\host-manager\WEB-INF\classes\hello
C:\Tomcat6\webapps\host-manager\WEB-INF\classes
C:\Tomcat6\webapps\host-manager\WEB-INF

Can someone pelase offer a suggestion and please tell me where the
CLASS file should actually reside? Please?

Hi..!
You need not keep the class file all over the place. goodness!
say test-site is the current webapp you are deploying, then,
all your class files would go into:
C:\Tomcat6\webapps\test-site\WEB-INF\classes\

all jsp/html files would be in:
C:\Tomcat6\webapps\test-site\

it seems like you have those files in right locations already.
try this:
package Hello.java into some package and place it in ...\WEB-INF
\classes folder

//Hello.java
package test;
class Hello {
...
...
}

you need NOT import Hello.* from your jsp, if you have placed right
file in right place.

this should be sufficient. please let me know if it helped.

ps. : follow coding standards, it will only benefit you.
 
T

tfrawley

Thank you, everyone, for your responses. I apologize, I am new to
Java, Tomcat, JSPs, etc. etc.

I am trying to distill everything everyone suggested so here goes:

Arne, once I get this working I will capitalize the class names. :)
Mark, that was because I was trying everything I could think of and
want ya'll to know that I had put the class file everywhere. I ended
up putting it everywhere except were it was supposed to go. :)
Nostalgia, Thanks for the info, I am going to try this again:

The name of the site is "test".

The "test" site's physical path is: C:\Tomcat6\webapps\test

I created a class file named "hello.class" and placed it in: C:
\Tomcat6\webapps\test\WEB-INF\classes

the contents of hello.class are:

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

This is just a text file I created in notepad guys, I didn't compile
it or anything. Maybe that is wrong, I don't know. :)

I created a JSP file named "index.jsp" the contents of which are:


<%@ page language="java"%>

<%
hello.hello h = new hello();
h.run();
%>


OR

<%@ page language="java"%>

<%
hello h = new hello();
h.run();
%>



All of which return the error that: hello cannot be resolved to a type



I REALLY appreciate your suggestions!! If I need to compile that
hello package then please, if possible, please provide the JRE command
line that would do the job cause I don't know how to do this... :(
 
A

Arne Vajhøj

Thank you, everyone, for your responses. I apologize, I am new to
Java, Tomcat, JSPs, etc. etc.

No need to apologize - everyone has to learn.
The name of the site is "test".

The "test" site's physical path is: C:\Tomcat6\webapps\test

I created a class file named "hello.class" and placed it in: C:
\Tomcat6\webapps\test\WEB-INF\classes

the contents of hello.class are:

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

That should be the content of hello.java and hello.class should be
in C:\Tomcat6\webapps\test\WEB-INF\classes\hello not
C:\Tomcat6\webapps\test\WEB-INF\classes (you need to let the
directory structure match the package structure).
This is just a text file I created in notepad guys, I didn't compile
it or anything. Maybe that is wrong, I don't know. :)

I created a JSP file named "index.jsp" the contents of which are:


<%@ page language="java"%>

<%
hello.hello h = new hello();
h.run();
%>

hello.hello h = new hello.hello();

when you do not have any import in your JSP.

Arne
 
N

Nostalgia

No need to apologize - everyone has to learn.








That should be the content of hello.java and hello.class should be
in C:\Tomcat6\webapps\test\WEB-INF\classes\hello not
C:\Tomcat6\webapps\test\WEB-INF\classes (you need to let the
directory structure match the package structure).





hello.hello h = new hello.hello();

when you do not have any import in your JSP.

Arne

aah..!

keeping just the .java file, how do u expect it to run!
of course you need to compile it,

c:\Tomcat6\webapps\test\WEB-INF\classes> javac -d . hello.java
your jsp should now work fine now.
 
T

tfrawley

You are right Nostalgia, Thank you!

Arne assisted me as well with the placement of the class file and now
it works!

YEAAAAAAAAAA!

Now comes all the work! haha!

Thank you all for your kind assistance and for not flaming me for a
newbie! I really appreciate everything!
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top