This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Kubernetes in Action and have Marko Luksa on-line!
See this thread for details.
Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem Regarding Accessing Java Bean From JSP  RSS feed

 
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
Java Linux Oracle
  • 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
Java Linux Oracle
  • 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 Ubuntu VI Editor
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!