Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   JSP Help Needed (http://www.velocityreviews.com/forums/t297929-jsp-help-needed.html)

sdavids 06-08-2006 03:01 PM

JSP Help Needed
 
Hey everyone I am trying to learn JSP although keep running into a
brick wall. I set up Tomcat 5.5 which is running fine, but I am trying
to import a Java class into a JSP page and it doesnt seem to work, this
is what my class looks like:

package steve;

public class TestMe {

public TestMe(){
System.out.println("INSIDE CONSTRUCTOR");
}

public int getNumber(){
return 10;
}
}

I saved the class as TestMe, and saved it in "\WEB-INF\classes\steve"

Now my JSP code is as follows:

<html>
<%@ page import="steve.TestMe.*" %>
<body>
<%
TestMe temp = new TestMe();
out.print("NUM=" + temp.getNumber());
%>
</body>
</html>

The error which I recieve when I run the jsp file is: TestMe cannot be
resolved to a type.

Any help would be phenominal.


nkalagarla@gmail.com 06-08-2006 03:07 PM

Re: JSP Help Needed
 
There is a problem in your import.

<%@ page import="steve.TestMe.*" %>

The above line should be like

<%@ page import="steve.*" %>
or
<%@ page import="steve.TestMe %>

sdavids wrote:
> Hey everyone I am trying to learn JSP although keep running into a
> brick wall. I set up Tomcat 5.5 which is running fine, but I am trying
> to import a Java class into a JSP page and it doesnt seem to work, this
> is what my class looks like:
>
> package steve;
>
> public class TestMe {
>
> public TestMe(){
> System.out.println("INSIDE CONSTRUCTOR");
> }
>
> public int getNumber(){
> return 10;
> }
> }
>
> I saved the class as TestMe, and saved it in "\WEB-INF\classes\steve"
>
> Now my JSP code is as follows:
>
> <html>
> <%@ page import="steve.TestMe.*" %>
> <body>
> <%
> TestMe temp = new TestMe();
> out.print("NUM=" + temp.getNumber());
> %>
> </body>
> </html>
>
> The error which I recieve when I run the jsp file is: TestMe cannot be
> resolved to a type.
>
> Any help would be phenominal.



sdavids 06-08-2006 03:08 PM

JSP Help Needed
 
p.s. I didnt do anything with the web.xml file, I dont know if that is
a problem or not, I really dont know what to do with it - I was under
the impression you only needed to modify it if you wanted to do
scriplets and such.


sdavids 06-08-2006 03:12 PM

Re: JSP Help Needed
 
I still get the same errors after changing the import statements with
both of yours


nkalagarla@gmail.com 06-08-2006 03:54 PM

Re: JSP Help Needed
 
Did you compile your java file? If not compile your java file and put
it in WEB-INF\classes\steve.

Also import should be like.

<%@ page import="steve.*" %>
or
<%@ page import="steve.TestMe"%>

sdavids wrote:
> I still get the same errors after changing the import statements with
> both of yours



Thomas Fritsch 06-08-2006 04:10 PM

Re: JSP Help Needed
 
sdavids schrieb:
> Hey everyone I am trying to learn JSP although keep running into a
> brick wall. I set up Tomcat 5.5 which is running fine, but I am trying
> to import a Java class into a JSP page and it doesnt seem to work, this
> is what my class looks like:
>
> package steve;
>
> public class TestMe {
>
> public TestMe(){
> System.out.println("INSIDE CONSTRUCTOR");
> }
>
> public int getNumber(){
> return 10;
> }
> }
>
> I saved the class as TestMe, and saved it in "\WEB-INF\classes\steve"

You have to save the class file as "TestMe.class", not as "TestMe".


--
Thomas

sdavids 06-08-2006 04:27 PM

Re: JSP Help Needed
 
Yes I have compiled the class, and I placed TestMe.class as well as
TestMe.java into the directory. Is there anything that I need to do in
the web..xml file in order for the jsp and java file to talk to one
another?


Timo Stamm 06-08-2006 05:15 PM

Re: JSP Help Needed
 
sdavids schrieb:
> Yes I have compiled the class, and I placed TestMe.class as well as
> TestMe.java into the directory.


Into which directory? It should be in

<webroot>/WEB-INF/classes/steve/TestMe.class


The JSP page can be anywhere in <webroot> (except restricted
directories). The import statement must be

steve.TestMe

or

steve.*


If that doesn't work, try importing a standard Java class like
java.util.ArrayList. If that works, add

static void main(String[] args) {System.out.println("hello world");}

to TestMe and try to run it with javac.

In other words: isolate the problem.


> Is there anything that I need to do in
> the web..xml file in order for the jsp and java file to talk to one
> another?


No.


Timo

sdavids 06-08-2006 06:22 PM

Re: JSP Help Needed
 

> The JSP page can be anywhere in <webroot> (except restricted
> directories). The import statement must be
>
> steve.TestMe


When I do that I get the error:
Generated servlet error:
Only a type can be imported. steve.TestMe resolves to a package


> or
>
> steve.*
>

Yet again it wont let me declare a new item of the TestMe type within
the JSP file, saying "TestMe cannot be resolved to a type"


Thomas Fritsch 06-09-2006 09:13 AM

Re: JSP Help Needed
 
sdavids wrote:
>>The JSP page can be anywhere in <webroot> (except restricted
>>directories). The import statement must be
>>
>> steve.TestMe

>
>
> When I do that I get the error:
> Generated servlet error:
> Only a type can be imported. steve.TestMe resolves to a package

To me this error message sounds pretty much that you might have a
*directory* "steve/TestMe" in your WEB-INF/classes area, instead of
having a *file* "steve/TestMe.class". I would suggest to carefully check
your WEB-INF/classes directory tree and mnaybe to delete and rebuild it
from scratch.
>
>
>
>>or
>>
>> steve.*
>>

>
> Yet again it wont let me declare a new item of the TestMe type within
> the JSP file, saying "TestMe cannot be resolved to a type"
>


--
Thomas


All times are GMT. The time now is 11:47 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.