Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display result using jsp:getProperty

 
hong zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:setProperty name="cashType" property="*">
should be:
<jsp:setProperty name="cashType" property="*"/>

Good luch
Ruilin
 
hong zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried and no luck. Any advice will be appreciated.
Thanks in advance.
 
hong zhang
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic