<%@ page import="myBean.*" %>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<jsp:useBean class="myBean.lineBean" id="mybean" scope="page" />
<%= mybean.stars(20) %>
</body>
</html>
inside the test folder. And I place the java file inside
c:\tomcat\webapps\examples\WEB-INF\classes\myBean. The content of the
file is as follow
package myBean;
public class lineBean
{
public String stars(int x)
{
String text = "<br>";
for (int i = 0; i < x; i++)
text = text + "*";
return text + "<br>";
}
}
And the Error message is:
Error: 500
Location: /test/test.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile Note:
sun.tools.javac.Main has been deprecated.
C:\tomcat\work\DEFAULT\test\test_1.java:4: Package myBean not found in
import.
import myBean.*;
^
1 error, 1 warning
at org.apache.tomcat.facade.JasperLiaison.javac(JspInterceptor.java:898)
at org.apache.tomcat.facade.JasperLiaison.processJspFile(JspInterceptor.java:733)
at org.apache.tomcat.facade.JspInterceptor.requestMap(JspInterceptor.java:506)
at org.apache.tomcat.core.ContextManager.processRequest(ContextManager.java:968)
at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:875)
at org.apache.tomcat.core.ContextManager.service(ContextManager.java:833)
at org.apache.tomcat.modules.server.Http10Interceptor.processConnection(Http10Interceptor.java:176)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:494)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:516)
at java.lang.Thread.run(Thread.java:536)
Do I need to put the java file in some correct directory before i use
the javaBean? Or I need to configure something inside tomcat to let it
know that where to get my JavaBean? Maybe I missed some important
steps, because this is my fisrt time try to run JSP with Java Bean.
I am appertiate to whom can help me to solve this problem!! Thank you.
The "examples" folder is a "web application" - your JSP must be located
in the same web application if you want it to be able to see that bean
class. Also, files under classes MUST be compiled class files, JSP
will not compile your .java files for you.
--
WBB
author: Cocoon 2 Programming, web publishing with XML and Java
http://www.lanw.com/books/cocoonbook/default.htm
Follow your instruction, I get the code work properly, kindly
apperciate to your help.