Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Problem with JSP on Tomcat Server 5.0.24

  Asked By: Madeline    Date: Jun 16    Category: Java    Views: 1290
  

I am having problem in running this jsp file with a javabean

JSP file - cter.jsp
<HTML>
<HEAD>
<TITLE> COUNTER FOR SHARP VIDEO </TITLE>
</HEAD>
<BODY>
<@page language="java" import="counter" />
<jsp:useBean id="test" class="counter" />
<jsp:setProperty name="counter" property="count" />
<% out.println("Count from scriplet code : " + counter.getcount() +"
<BR>"); %>
Count from jsp: getproperty: <jsp:getProperty name="girish"
property="count" /> <BR>

</BODY>
</HTML>

Javabean file counter.java

public class counter
{
int count=0;

public counter()
{ }


public int getcount()
{
count++;
return this.count;
}

public void setcount(int count) {

this.count=count;}
}

JSP file is under F:\jakarta-tomcat-5.0.24\webapps\ROOT
counter.java is complied using javac &
counter.class file is under
F:\jakarta-tomcat-5.0.24\webapps\ROOT\WEB-INF\classes
JAVA_HOME IS ALSO SET
TOMCAT IS GIVING ERROR AS

org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 13 in the jsp file: /cter.jsp
Generated servlet error:
[javac] Compiling 1 source file
F:\Jakarta\jakarta-tomcat-5.0.24\work\Catalina\localhost\_\org\apache\jsp\cter_j\
sp.java:54: cannot resolve symbol
symbol : class counter
location: class org.apache.jsp.cter_jsp
counter test = null;
^

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Lurline Fischer     Answered On: Jun 16

Try putting you counter  class in a package.

So, in the first line  of your counter.java class, you would have a
line like:

package beans;

public class  counter ...

(You should arrange source  files in a directory tree that reflects
their package tree. In case you've never worked with packages before,
when you compile  counter.java, you have to have it in a directory
called "beans". Run the javac  compiler in the directory just above
the beans directory.
e.g. javac beans\counter.java)

Then create a directory called beans in the classes directory. Put
the compiled class file  in the directory:
F:\jakarta-tomcat-5.0.24\webapps\ROOT\WEB-INF\classes\beans\


Finally,
change your jsp  to the following:

...
<@page language="java" import="beans.counter" />
<jsp:useBean id="test" class="beans.counter" />
...

Of course, you can name the package anything you like.
Honestly, I'm not exactly sure why it can't find your class, but this
should work - and packages are actually common practice anyway.

See if this works for you.

 
Didn't find what you were looking for? Find more on Problem with JSP on Tomcat Server 5.0.24 Or get search suggestion and latest updates.




Tagged: