Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem Regarding Accessing Java Bean From JSP

 
Krishna Potluri
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.
 
Sergio Tridente
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 ]
 
Pedro Lobato Sena
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"/>
 
Christophe Verré
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic