You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dan Lovell <dl...@mcs.net> on 2000/11/06 16:51:45 UTC

JSP getProperty issue - does not return data

Is anyone having trouble using the JSP tags for set and get property.
They do not seem to work.  I am using Tomcat 3.1 on Win NT.

<td><%= addrsProfile.getCity() %>   </td> ********  works **********
<td><jsp:getProperty name="addrsProfile" property="city"/> </td>  ****
does not work *****

Here is my JSP page:

<%@ page contentType="text/html;charset=WINDOWS-1252"%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;
charset=WINDOWS-1252">
<META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
<TITLE>
JSP Issue - Get Property
</TITLE>
</HEAD>
<BODY>
<H2>The following output is from JSP code:</H2>

<jsp:useBean id="profile"  class="proto.Profile">
  <jsp:setProperty  name="profile" property="account" value = "18190" />

</jsp:useBean>

<jsp:useBean  id="addrsProfile" class="proto.Address">
</jsp:useBean>

<%
  proto.Address addrs  = profile.loadAddresses("18190");
  addrsProfile = addrs;
%>

<table>
<tr><th colspan="2"> Address Information for Client </th></tr>
<tr><td>City 1</td><td>City 2</td>
<tr>
<td><%= addrsProfile.getCity() %>   </td>
<td><jsp:getProperty name="addrsProfile" property="city"/> </td>
</tr>
</table>

</HTML>

Any help would be great.
Thanks


RE: JSP getProperty issue - does not return data

Posted by Toby Piper <tp...@CompCraft.com>.
If you haven't already solved this try adding a get of the property you just set
to see if it is being set.

Also a tip for debugging, you can do System.out's in your code and see the
output on the console window or in the log.

public  void setAccount(String account){
 this.account  = account;
 if (g_DEBUG == true) System.out.println( "Account =" + account );
}

You can actually make DEBUG a property of your beans that you can set and then
turn it on in your JSP and not have to recompile which makes for easier
debugging and it can be left there all the time if you set the default value to
be false. Then you can delete the setDEBUG line in your JSP and nobody will know
it's there.

Suggestions:
 - Try not setting the property inside of the useBean tag
 - You don't need to do the closing useBean tag, just put a /> on the end of the
opening tag.

<jsp:useBean id="profile"  class="proto.Profile"/>
<jsp:setProperty  name="profile" property="debug" value = "1" />
<jsp:setProperty  name="profile" property="account" value = "18190" />
<b><% profile.getAccount %><br>
<jsp:getProperty name="profile" property="account" /> </b><br>

<jsp:useBean  id="addrsProfile" class="proto.Address"/>

<%
   proto.Address addrs  = profile.loadAddresses("18190");
   addrsProfile = addrs;
%>

> -----Original Message-----
> From: Dan Lovell [mailto:dlovell@mcs.net]
> Sent: Monday, November 06, 2000 11:22 AM
> To: tomcat-user@jakarta.apache.org
> Subject: Re: JSP getProperty issue - does not return data
>
>
> Here are my two beans:
>
> Profile:
> package proto;
>
> import java.util.*;
> import java.sql.*;
>
> public class Profile {
>
>   private String  account;
>
> public Profile() {
>   super();
> }
>
> public Profile ( String account ) {
>  super();
> }
>
> public  void setAccount(String account){
>   this.account  = account;
> }
>
> public  String  getAccount() {
> return  this.account;
> }
>
> public Address loadAddresses(String account) {
>  Address addr = new Address();
>  addr.setAccount(account);
>  return addr;
> }
> }
>
> Address:
>
> package proto;
>
> import java.util.*;
> import java.sql.*;
>
> public class Address {
>
>  private String city;
>  private String account;
>
>  public Address() {
>   super();
>   this.city = null;
>   this.account = null;
>
>  }
>
>  public Address(
>   String account,
>   String city ) {
>
>   this.account = account;
>   this.city = city;
>
>  }
>
>  public Address(String account) {
>   this.setAccount(account);
>  }
>
>  public java.lang.String getAccount() {
>   return account;
>  }
>
>  public void setAccount(java.lang.String newAccount) {
>   account = newAccount;
>  }
>
>
>  public java.lang.String getCity() {
>   return city;
>  }
>
>  public void setCity(java.lang.String newCity) {
>   city = newCity;
>  }
>
> }
>
> Thanks for any help
>
> Toby Piper wrote:
>
> > get/set work fine for me.
> >
> > If I take your code/notes literally then you are outputting the JSP
> tags instead
> > of actually executing them. However if this is your actual code
> then it looks
> > Ok.
> >
> > You might try putting the useBean tag before any HTML tags - however I don't
> > think that's supposed to matter, but it's where mine are and they
> work there.
> >
> > I suspect the problem is with your JAVA code itself. We need to look at your
> > java code to see if you are calling it properly from the JSP. So
> please post an
> > example of your code.
> >
> > > -----Original Message-----
> > > From: Dan Lovell [mailto:dlovell@mcs.net]
> > > Sent: Monday, November 06, 2000 7:52 AM
> > > To: tomcat-user@jakarta.apache.org
> > > Subject: JSP getProperty issue - does not return data
> > >
> > >
> > > Is anyone having trouble using the JSP tags for set and get property.
> > > They do not seem to work.  I am using Tomcat 3.1 on Win NT.
> > >
> > > <td><%= addrsProfile.getCity() %>   </td> ********  works **********
> > > <td><jsp:getProperty name="addrsProfile" property="city"/> </td>  ****
> > > does not work *****
> > >
> > > Here is my JSP page:
> > >
> > > <%@ page contentType="text/html;charset=WINDOWS-1252"%>
> > > <HTML>
> > > <HEAD>
> > > <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> > > charset=WINDOWS-1252">
> > > <META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
> > > <TITLE>
> > > JSP Issue - Get Property
> > > </TITLE>
> > > </HEAD>
> > > <BODY>
> > > <H2>The following output is from JSP code:</H2>
> > >
> > > <jsp:useBean id="profile"  class="proto.Profile">
> > >   <jsp:setProperty  name="profile" property="account" value = "18190" />
> > >
> > > </jsp:useBean>
> > >
> > > <jsp:useBean  id="addrsProfile" class="proto.Address">
> > > </jsp:useBean>
> > >
> > > <%
> > >   proto.Address addrs  = profile.loadAddresses("18190");
> > >   addrsProfile = addrs;
> > > %>
> > >
> > > <table>
> > > <tr><th colspan="2"> Address Information for Client </th></tr>
> > > <tr><td>City 1</td><td>City 2</td>
> > > <tr>
> > > <td><%= addrsProfile.getCity() %>   </td>
> > > <td><jsp:getProperty name="addrsProfile" property="city"/> </td>
> > > </tr>
> > > </table>
> > >
> > > </HTML>
> > >
> > > Any help would be great.
> > > Thanks
> > >
> > >
>
>


Re: JSP getProperty issue - does not return data

Posted by Dan Lovell <dl...@mcs.net>.
Here are my two beans:

Profile:
package proto;

import java.util.*;
import java.sql.*;

public class Profile {

  private String  account;

public Profile() {
  super();
}

public Profile ( String account ) {
 super();
}

public  void setAccount(String account){
  this.account  = account;
}

public  String  getAccount() {
return  this.account;
}

public Address loadAddresses(String account) {
 Address addr = new Address();
 addr.setAccount(account);
 return addr;
}
}

Address:

package proto;

import java.util.*;
import java.sql.*;

public class Address {

 private String city;
 private String account;

 public Address() {
  super();
  this.city = null;
  this.account = null;

 }

 public Address(
  String account,
  String city ) {

  this.account = account;
  this.city = city;

 }

 public Address(String account) {
  this.setAccount(account);
 }

 public java.lang.String getAccount() {
  return account;
 }

 public void setAccount(java.lang.String newAccount) {
  account = newAccount;
 }


 public java.lang.String getCity() {
  return city;
 }

 public void setCity(java.lang.String newCity) {
  city = newCity;
 }

}

Thanks for any help

Toby Piper wrote:

> get/set work fine for me.
>
> If I take your code/notes literally then you are outputting the JSP tags instead
> of actually executing them. However if this is your actual code then it looks
> Ok.
>
> You might try putting the useBean tag before any HTML tags - however I don't
> think that's supposed to matter, but it's where mine are and they work there.
>
> I suspect the problem is with your JAVA code itself. We need to look at your
> java code to see if you are calling it properly from the JSP. So please post an
> example of your code.
>
> > -----Original Message-----
> > From: Dan Lovell [mailto:dlovell@mcs.net]
> > Sent: Monday, November 06, 2000 7:52 AM
> > To: tomcat-user@jakarta.apache.org
> > Subject: JSP getProperty issue - does not return data
> >
> >
> > Is anyone having trouble using the JSP tags for set and get property.
> > They do not seem to work.  I am using Tomcat 3.1 on Win NT.
> >
> > <td><%= addrsProfile.getCity() %>   </td> ********  works **********
> > <td><jsp:getProperty name="addrsProfile" property="city"/> </td>  ****
> > does not work *****
> >
> > Here is my JSP page:
> >
> > <%@ page contentType="text/html;charset=WINDOWS-1252"%>
> > <HTML>
> > <HEAD>
> > <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> > charset=WINDOWS-1252">
> > <META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
> > <TITLE>
> > JSP Issue - Get Property
> > </TITLE>
> > </HEAD>
> > <BODY>
> > <H2>The following output is from JSP code:</H2>
> >
> > <jsp:useBean id="profile"  class="proto.Profile">
> >   <jsp:setProperty  name="profile" property="account" value = "18190" />
> >
> > </jsp:useBean>
> >
> > <jsp:useBean  id="addrsProfile" class="proto.Address">
> > </jsp:useBean>
> >
> > <%
> >   proto.Address addrs  = profile.loadAddresses("18190");
> >   addrsProfile = addrs;
> > %>
> >
> > <table>
> > <tr><th colspan="2"> Address Information for Client </th></tr>
> > <tr><td>City 1</td><td>City 2</td>
> > <tr>
> > <td><%= addrsProfile.getCity() %>   </td>
> > <td><jsp:getProperty name="addrsProfile" property="city"/> </td>
> > </tr>
> > </table>
> >
> > </HTML>
> >
> > Any help would be great.
> > Thanks
> >
> >


RE: JSP getProperty issue - does not return data

Posted by Toby Piper <tp...@CompCraft.com>.
get/set work fine for me.

If I take your code/notes literally then you are outputting the JSP tags instead
of actually executing them. However if this is your actual code then it looks
Ok.

You might try putting the useBean tag before any HTML tags - however I don't
think that's supposed to matter, but it's where mine are and they work there.

I suspect the problem is with your JAVA code itself. We need to look at your
java code to see if you are calling it properly from the JSP. So please post an
example of your code.

> -----Original Message-----
> From: Dan Lovell [mailto:dlovell@mcs.net]
> Sent: Monday, November 06, 2000 7:52 AM
> To: tomcat-user@jakarta.apache.org
> Subject: JSP getProperty issue - does not return data
>
>
> Is anyone having trouble using the JSP tags for set and get property.
> They do not seem to work.  I am using Tomcat 3.1 on Win NT.
>
> <td><%= addrsProfile.getCity() %>   </td> ********  works **********
> <td><jsp:getProperty name="addrsProfile" property="city"/> </td>  ****
> does not work *****
>
> Here is my JSP page:
>
> <%@ page contentType="text/html;charset=WINDOWS-1252"%>
> <HTML>
> <HEAD>
> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;
> charset=WINDOWS-1252">
> <META NAME="GENERATOR" CONTENT="Oracle JDeveloper">
> <TITLE>
> JSP Issue - Get Property
> </TITLE>
> </HEAD>
> <BODY>
> <H2>The following output is from JSP code:</H2>
>
> <jsp:useBean id="profile"  class="proto.Profile">
>   <jsp:setProperty  name="profile" property="account" value = "18190" />
>
> </jsp:useBean>
>
> <jsp:useBean  id="addrsProfile" class="proto.Address">
> </jsp:useBean>
>
> <%
>   proto.Address addrs  = profile.loadAddresses("18190");
>   addrsProfile = addrs;
> %>
>
> <table>
> <tr><th colspan="2"> Address Information for Client </th></tr>
> <tr><td>City 1</td><td>City 2</td>
> <tr>
> <td><%= addrsProfile.getCity() %>   </td>
> <td><jsp:getProperty name="addrsProfile" property="city"/> </td>
> </tr>
> </table>
>
> </HTML>
>
> Any help would be great.
> Thanks
>
>