• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help coding examples

 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am having trouble with Tomcat 5.0.28.

I am pretty sure that my classes are in WEB-INF/classes.

I am trying to use both jsp:useBean and jsp:getProperty. Tomcat is complaining about the following:

org.apache.jasper.JasperException: /EL.jsp(4,0) The value for the useBean class attribute com.arnab.Person is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)

Here is my JSP code:
<html>
<body>

<%@ page import="person.arnab.*" %>

<jsp:useBean id="person" class="com.arnab.Person" scope="request" />

Name of Person is: <jsp:getProperty name="person" property="name" />

Name of Person's pet is: <%= person.getPet().getName() %>

</body>
</html>
Here is my servlet code:

package com.arnab;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.arnab.*;

public class elServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException
{

Person P = new Person();
Pet T = new Pet();

response.setContentType("text/html");

P.setName(request.getParameter("name"));
T.setName(request.getParameter("pname"));
P.setPet(T);

request.setAttribute("person",P);

RequestDispatcher view = request.getRequestDispatcher("/EL.jsp");

view.forward(request,response);
}
}

Here are my Person and Pet class:

package com.arnab;

class Pet
{
private String name;

public void setName ( String nm ){
this.name = nm;
}

public String getName() {
return name;
}

};

class Person
{
private String name;
private Pet pet;

public void setName ( String nm ){
this.name = nm;
}

public String getName() {
return name;
}

public void setPet (Pet p) {
this.pet = p;
}

public Pet getPet () {
return pet;
}

}
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks wrong:

 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was definitely wrong -
page import="person.arnab.*"

It should be page import="com.arnab.*"

However that didnt help: here is the stack trace:

org.apache.jasper.JasperException: /EL.jsp(6,0) The value for the useBean class attribute com.arnab.Person is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:150)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1227)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java: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.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
com.arnab.elServlet.doPost(elServlet.java:28)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 
Arnab Sinha
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured out the problem. Both Person and Pet should be public. I had them as default.

Thank you for your response.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic