![]() |
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. |
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. |
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. |
Re: JSP Help Needed
I still get the same errors after changing the import statements with
both of yours |
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 |
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 |
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? |
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 |
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" |
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 03:32 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.