*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Problem Regarding Accessing Java Bean From JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Problem Regarding Accessing Java Bean From JSP" Watch "Problem Regarding Accessing Java Bean From JSP" New topic
Author

Problem Regarding Accessing Java Bean From JSP

Krishna Potluri
Greenhorn

Joined: Apr 20, 2007
Posts: 19
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

Joined: Mar 22, 2007
Posts: 329

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 ]

SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
Pedro Lobato Sena
Greenhorn

Joined: Apr 25, 2006
Posts: 16
Hi,

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

Regards


SCWCD<br />SCJP<br /> <br />Pedro Henrique Lobato Sena
Krishna Potluri
Greenhorn

Joined: Apr 20, 2007
Posts: 19
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

Joined: Mar 22, 2007
Posts: 329

Please try:

<jsp:setProperty name="dogRef" property="nickName" value="Fido"/>
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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.


[My Blog]
All roads lead to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem Regarding Accessing Java Bean From JSP
 
Similar Threads
Accessing Java Bean Property From JSP
Accessing Java Bean Using JSP Action Tag
El property not found problem
Simple EL code is not working
Java Bean