aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jspuseBean error?? 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 "jspuseBean error??" Watch "jspuseBean error??" New topic
Author

jspuseBean error??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Hi Guys,

I have the following code just to test the working of jsp:useBean and I'm getting the error as shown. First the code,

The html file,

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample EL Project</title>
</head>
<body>
This is to sample application to test JSP 2.0's EL feature!
<form action = "ELServlet.do" method="GET">
Username<input type=text name=Username>
Password<input type=text name=Password>
<input type=submit value=submit>
</form>
</body>
</html>

The ELServlet.do, just transfetrs control to test.jsp


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
RequestDispatcher dispatcher =
request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request, response);
}

The test.jsp file,

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="com.example.*" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Test Page for EL!</title>
</head>
<body>
<jsp:useBean id="userclass" class="com.example.UserClass" scope="page"/>
<jsp:setProperty name="userclass" property="*" />

<jsp:getProperty name="userclass" property="Username" />
</body>
</html>

The user class (bean class)

package com.example;

public class UserClass {
private String Username;
private String Password;
public UserClass(){}

public void setUsername(String value){
Username = value;
}
public void setPassword(String value){
Password = value;
}

public String getUsername(){
return Username;
}
public String getPassword(){
return Password;
}
}

And here is the error that I get,

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Cannot find any information on property 'Username' in a bean of type 'com.example.UserClass'
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:837)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1015)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1062)
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.example.ELServlet.doGet(ELServlet.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

What could be the problem guys??


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Replace
<jsp:getProperty name="userclass" property="Username" />
with
<jsp:getProperty name="userclass" property="username" />


[My Blog]
All roads lead to JavaRanch
Tridib Samanta
Ranch Hand

Joined: Apr 28, 2004
Posts: 128
Use this:

<jsp:getProperty name="userclass" property="username" />


Read JavaBean property naming convention; that will help you fix this type of problems.


Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Satou,

When I did what you said, I'm getting null as the o/p. But I have a doubt as to why I should replace Username as username???
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Any reason as to why I'm getting null as the o/p? I tried changing the scope from page to request even after which I'm getting null as the o/p?
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

All right guys, I got it to work! Thanks for the help offered.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

But I have a doubt as to why I should replace Username as username???

This is a JavaBean convention. Properties are supposed to start with a lowercase letter.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9383
    
    2

Satou,

I understood my mistake! Thanks for clarifying!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jspuseBean error??