• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Problem Regarding Accessing Java Bean From JSP

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Two java beans with names Person.java and Dog.java
My question is how to set property Dog of Person java bean using <jsp:setProperty > action tag in temp.jsp.
___________________________________________________________________________
******Person.java*******
public class Person {
private Dog dog;

public void setDog(Dog dog) {

this.dog = dog;
}


public Dog getDog(){

return dog;
}
}


************Dog.java **********

public class Dog {
private String nickName = "";

public void setNickName(String nickName){

this.nickName = nickName;
}

public String getNickName() {

return nickName;
}

}


************temp.jsp****

<html>
<body>
<jsp:useBean id="p1" class="Person"/>
<jsp:setProperty name="p1" property="dog" value=" "/>
</body>
</html>
____________________________________________________________________________

Thanks in advance.

Thanks and Regards,
Krishna.
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try something like this:



Note: It would be a good idea to put both classes (Dog and Person) inside a package. If you do so, you'll need to specify the fully-qualified name in the "class" attribute of the jsp:useBean tag.
[ May 02, 2007: Message edited by: Sergio Tridente ]
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In this situations, you have to get the object through expressions.

Regards
 
Krishna Potluri
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

When I run the application as specified you i am getting exception. kindly help me to resolve it.






Kindly help me tom resolve the issue.

Thanks and Regards,
Kris.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please try:

<jsp:setProperty name="dogRef" property="nickName" value="Fido"/>
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The value for the useBean class attribute com.kris.jsp.Dog is invalid


Where did you put the Dog.class file ? Please give the full path.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!