Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JSP/JavaBean - Newbie help

Reply
Thread Tools

JSP/JavaBean - Newbie help

 
 
Dave
Guest
Posts: n/a
 
      10-01-2006
I have set-up Apache Tomcat for the first time and I'm trying to configure a
test JSP website on it. I'm attempting to use a simple JavaBean with my JSP
page and I keep getting errors relating to the JavaBean.

index.jsp is in the $CATALINA_HOME\webapps\JSPTest\WebContent

SimpleBean.java is in $CATALINA_HOME\webapps\JSPTest\src\mybeans

SimpleBean.class is in
$CATALINA_HOME\webapps\JSPTest\WebContent\WEB-INF\classes\mybeans

web.xml is in $CATALINA_HOME\webapps\JSPTest\WebContent\WEB-INF\


If I change the "type" attribute of the jsp:useBean tag then to "class" then
I get a different exception (shown below).

I'm using Tomcat 5.5 for Windows, JRE/JDK 1.5. I have tried uninstalling and
re-installing Tomcat, and also tried running it as both a service and a
standalone application.

Any idea what the problem is? I presume it's something fundamental I'm
missing.

Thanks in advance, code and errors are below.

********
index.jsp
********

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="mybeans.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Using SimpleBean</title>
</head>
<body>
<jsp:useBean id="msg" type="SimpleBean" />
Test Content
</body>
</html>


*************
SimpleBean.java
*************

package mybeans;
public class SimpleBean
{
private String message;
public SimpleBean()
{
}
public void setMessage(String input)
{
message = input;
}
public String getMessage()
{
return message;
}
}



*******
web.xml
*******

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
JSPTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>SimpleBean</servlet-name>
<servlet-class>SimpleBean</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SimpleBean</servlet-name>
<url-pattern>/servlet/SimpleBean</url-pattern>
</servlet-mapping>
</web-app>



*********
Exception 1
*********

description The server encountered an internal error () that prevented it
from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 13 in the jsp file: /WebContent/index.jsp
Generated servlet error:
SimpleBean cannot be resolved to a type

An error occurred at line: 13 in the jsp file: /WebContent/index.jsp
Generated servlet error:
SimpleBean cannot be resolved to a type


org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:512) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)root causeorg.apache.jasper.JasperException: Unable to compile class for JSPAn error occurred at line: 13 in the jsp file: /WebContent/index.jspGenerated servlet error:SimpleBean cannot be resolved to a typeAn error occurred at line: 13 in the jsp file: /WebContent/index.jspGenerated servlet error:SimpleBean cannot be resolved to a type org.apache.jasper.compiler.DefaultErrorHandler.jav acError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacEr ror(ErrorDispatcher.java:32 org.apache.jasper.compiler.JDTCompiler.generateCla ss(JDTCompiler.java:414) org.apache.jasper.compiler.Compiler.compile(Compil er.java:297) org.apache.jasper.compiler.Compiler.compile(Compil er.java:276) org.apache.jasper.compiler.Compiler.compile(Compil er.java:264) org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:305) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)note The full stack trace of the root cause is available in the ApacheTomcat/5.5.20 logs.********Exception 2*********description The server encountered an internal error () that prevented itfrom fulfilling this request.exceptionorg.apache.jasper.JasperException : Unable to load class for JSP org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:512) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)root causeorg.apache.jasper.JasperException: Unable to load class for JSP org.apache.jasper.JspCompilationContext.load(JspCo mpilationContext.java:59 org.apache.jasper.servlet.JspServletWrapper.getSer vlet(JspServletWrapper.java:147) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)root causejava.lang.ClassNotFoundException: org.apache.jsp.WebContent.index_jsp java.net.URLClassLoader$1.run(Unknown Source) java.security.AccessController.doPrivileged(Native Method) java.net.URLClassLoader.findClass(Unknown Source) org.apache.jasper.servlet.JasperLoader.loadClass(J asperLoader.java:133) org.apache.jasper.servlet.JasperLoader.loadClass(J asperLoader.java:65) org.apache.jasper.JspCompilationContext.load(JspCo mpilationContext.java:596) org.apache.jasper.servlet.JspServletWrapper.getSer vlet(JspServletWrapper.java:147) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:317) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)note The full stack trace of the root cause is available in the ApacheTomcat/5.5.20 logs.***************************Exception 3 (using "class" instead of "type" attribute)***************************description The server encountered an internal error () that prevented itfrom fulfilling this request.exceptionorg.apache.jasper.JasperException : /WebContent/index.jsp(13,0) The value forthe useBean class attribute SimpleBean is invalid. org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:512) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)root causeorg.apache.jasper.JasperException: /WebContent/index.jsp(13,0) The value forthe useBean class attribute SimpleBean is invalid. org.apache.jasper.compiler.DefaultErrorHandler.jsp Error(DefaultErrorHandler.java:39) org.apache.jasper.compiler.ErrorDispatcher.dispatc h(ErrorDispatcher.java:405) org.apache.jasper.compiler.ErrorDispatcher.jspErro r(ErrorDispatcher.java:146) org.apache.jasper.compiler.Generator$GenerateVisit or.visit(Generator.java:1174) org.apache.jasper.compiler.Node$UseBean.accept(Nod e.java:1116) org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:2163) org.apache.jasper.compiler.Node$Visitor.visitBody( Node.java:2213) org.apache.jasper.compiler.Node$Visitor.visit(Node .java:2219) org.apache.jasper.compiler.Node$Root.accept(Node.j ava:456) org.apache.jasper.compiler.Node$Nodes.visit(Node.j ava:2163) org.apache.jasper.compiler.Generator.generate(Gene rator.java:3320) org.apache.jasper.compiler.Compiler.generateJava(C ompiler.java:19 org.apache.jasper.compiler.Compiler.compile(Compil er.java:295) org.apache.jasper.compiler.Compiler.compile(Compil er.java:276) org.apache.jasper.compiler.Compiler.compile(Compil er.java:264) org.apache.jasper.JspCompilationContext.compile(Js pCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:305) org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet .java:802)note The full stack trace of the root cause is available in the ApacheTomcat/5.5.20 logs.

 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      10-02-2006
Dave wrote:
> ********
> index.jsp
> ********
>
> <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
> pageEncoding="ISO-8859-1"%>
> <%@ page import="mybeans.*" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


It's better to use the lower-case "html"; this will prepare you better for XHTML.

> <html>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
> <title>Using SimpleBean</title>
> </head>
> <body>
> <jsp:useBean id="msg" type="SimpleBean" />
> Test Content
> </body>
> </html>


<jsp:useBean id="msg" class="mybeans.SimpleBean" />

I don't think the <%@ page import="mybeans.*" %> works to prevent the need to
fully qualify the class in a <jsp:useBean ... /> tag. I easily could be
mistaken here, but the Sun docs refer to
<jsp:useBean id="beanName" class="fully_qualified_classname" scope="scope" />

http://java.sun.com/j2ee/1.4/docs/tu...doc/index.html

> *************
> SimpleBean.java
> *************
>
> package mybeans;
> public class SimpleBean
> {
> ...
> }


> *******
> web.xml
> *******
>
> <servlet>
> <servlet-name>SimpleBean</servlet-name>
> <servlet-class>SimpleBean</servlet-class>
> </servlet>


SimpleBean is not a servlet.

> SimpleBean.class is in
> $CATALINA_HOME\webapps\JSPTest\WebContent\WEB-INF\classes\mybeans
>
> web.xml is in $CATALINA_HOME\webapps\JSPTest\WebContent\WEB-INF\


You should install the app in the webapps/ directory directly, not one level
down in WebContent/, i.e.,

$CATALINA_HOME/webapps/JSPTest/index.jsp
$CATALINA_HOME/webapps/JSPTest/WEB-INF/
$CATALINA_HOME/webapps/JSPTest/WEB-INF/classes/...

If WEB-INF/ is buried one level down then the container cannot find the
classes/ subdirectory.

http://java.sun.com/j2ee/1.4/docs/tu....html#wp225219
http://tomcat.apache.org/tomcat-5.5-...eployment.html

- Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newbie with newbie questions JohnE ASP .Net 3 08-17-2009 10:10 PM
VONAGE Newbie w/newbie question New_kid@nowhere.new VOIP 0 08-11-2007 01:40 PM
another newbie question from another newbie.... Lee UK VOIP 4 05-17-2005 04:10 PM
newbie: cisco vlan newbie question No Spam Cisco 3 06-07-2004 10:02 AM
Newbie! I'm a newbie! What's wrong with this program? Id0x Python 4 07-20-2003 11:40 PM



Advertisments