File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Help for a  simple jSP program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Help for a  simple jSP program" Watch "Help for a  simple jSP program" New topic
Author

Help for a simple jSP program

Jaya Nettem
Greenhorn

Joined: May 10, 2005
Posts: 24
Hi,

I am trying to a very simple JSP program and it is not working.
Here is the listing:

BasicCounter.jsp
------------------------------
<html><body>
Basic Counter: Page Count is:
<%
out.println(foo.Counter.getCount());
%>
</body></html>
-------------------------------


Counter.java
------------------------

package foo;

public class Counter {

private static int count;
public static int getCount()
{
count++;
return count;
}
}

I have compiled Counter.java and placed it in webapps/MyApp/WEB-INF/classes/foo

When I try to bring up JSP page, I get the error saying that
"class Counter not found".

I even tried removing the package statement from Counter.java and compiled it and placed it in appropriate place. It still fails. Am I missing some path variables .. or something of that sort ?
By the way I am using Tomcat 4.1 for testing.

PLEEEEEEEEESE HELP !

I have wasted a lot of time on this.

Thanks in advance.

Jaya
sergio mendez-rueda
Ranch Hand

Joined: May 12, 2005
Posts: 37
hi nettem,

1.- place your BasicCounter.jsp in:
webapps/Myapp
2.- start tomcat
3.- call in your browser:
http://localhost:8080/Myapp/BasicCounter.jsp
(8080 is the default port of tomcat;-)
the file and directory structure os your web app must be somethink like that:
webapps/Myapp

enjoy tomcat (why are you using tomcat version 4.1??)
Sanjay pts
Ranch Hand

Joined: Nov 07, 2000
Posts: 357
I think you have to import class using
<%@ page import="foo.Counter" %>

thanx
sanjay


Eat JAVA, Drink JAVA, Sleep Java
Jaya Nettem
Greenhorn

Joined: May 10, 2005
Posts: 24
Thanks for your replies.

I tried both approaches (importing/and specifying complete path ... of course separately ...) and the rest needed (I am following HF Series for Servlets and JSPs) .. I still get the same error ... I even tried not specifying the package at all ... so that I do not have to import and the class could go straight into WEB-INF/classes directory ... still Counter class is not recognised) ... I tested the JSP without using the Counter class .. it works fine (so I know that web.xml is correct) ...
seemapanth Joshi
Ranch Hand

Joined: Nov 28, 2004
Posts: 47
tried both approaches (importing/and specifying complete path ... of course separately ...)


Using both together should not give you any problems either.

(so I know that web.xml is correct) ...

I don't think you need anything in web.xml for this to run.

I would suggest looking at your Tomcat log files located at tomcat-home\logs. Could there be a relation between what it is reading from the DD and the locating of the counter class. By the way I copied your scenario and it works perfectly for me, so it could be something else.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help for a simple jSP program