aspose file tools*
The moose likes Servlets and the fly likes display result using jsp:getProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "display result using jsp:getProperty" Watch "display result using jsp:getProperty" New topic
Author

display result using jsp:getProperty

hong zhang
Ranch Hand

Joined: Jun 07, 2001
Posts: 30
Hi.
I'm unable to use jsp:getProperty to display result, any help will be apprecialted. The bean has getter and setter. My code is:
<%@ page import="java.sql.*"%>
<%@ page import="db.cashTypeBean"%>
<jsp:useBean id="cashType" class="db.cashTypeBean">
<jsp:setProperty name="cashType" property="*">
<%
Connection conn = null;
Statement stat = null;
ResultSet result = null;
cashTypeBean cType = new cashTypeBean();
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
...
if(result.next()){
System.out.println(cash type:" + results.getString("CSH_TYP_CD")); // ok, i got the data
cType.setCode(results.getString("CSH_TYPE_CD"));
cType.setName(results.getString("LKUP_NM"));
}
connection.close():
}catch...{}
finally{}
%>
</jsp:userBean>
<html>
<body>
<p>
Cash Type =
<jsp:getProperty name="cashType" property="code"/>
<p>
Description =
<jsp:getProperty name="cashType" property="name"/>
</body>
</html>
Thanks in advance.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
The classic trap here is caused if your public bean variable name does not start with a lower case letter, the reflection system implied by the line:
<jsp:setProperty name="cashType" property="*">
does not work. Your variable must be public and start with a lower case letter. Your setter and getter must use the same name BUT with the initial letter upper case.
Bill

------------------
author of:
ruilin yang
Ranch Hand

Joined: Feb 25, 2001
Posts: 334
<jsp:setProperty name="cashType" property="*">
should be:
<jsp:setProperty name="cashType" property="*"/>

Good luch
Ruilin
hong zhang
Ranch Hand

Joined: Jun 07, 2001
Posts: 30
Mr. Brogden,
Thank you for your response.
Here's the code for bean:
package db;
import java.util.*;
public class cashTypeBean{
public string code;
public string name;
public void setCode(String code){
this.code = code;
}
pubic void setName(String name){
this.name = name;
{
public String getCode(){
return code;
}
public String getName(){
return name;
}
}
My public variables in the bean begin with lower case. Could you elaberate more what I did wrong.
Thank you very much!
hong zhang
Ranch Hand

Joined: Jun 07, 2001
Posts: 30
I tried and no luck. Any advice will be appreciated.
Thanks in advance.
hong zhang
Ranch Hand

Joined: Jun 07, 2001
Posts: 30
Thanks, ruilin. I tried this, but still din not work.
<jsp:setProperty name="cashType" property="*"/>
Any other ideas? Thanks in advance!
Hong
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12836
    
    5
That certainly looks right. Exactly what happens when you access the JSP page?
I hope you are testing using a simplified version without database access. Do you have an error page defined for this JSP?
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display result using jsp:getProperty