• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

display result using jsp:getProperty

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:
 
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic