Jsp:useBean

Hi all,

I want to know how all the proerpties get set in Jsp page by using Jsp:useBean tag.

If i write <%jsp:setProperty name = id propertyr="*" %>

how all the attributes defined in JspBean get set by the set meyhode.

by which they are being called

internally.

[304 byte] By [nitin_82a] at [2007-10-2 20:34:53]
# 1

hi ,

i will explain by taking an example

(I)This is my bean class

public class Person1 {

public String getAddress()

{

return address;

}

public void setAddress(String address) {

this.address = address;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNumber() {

return number;

}

public void setNumber(int number) {

this.number = number;

}

private int number;

private String name1;

private String address;

}

(II) this is my JSP file by name form.jsp

<center>

<form method="post">

Enter ur number:<input type="text" name="number">

Enter ur name:<input type="text" name="name1">

Enter ur address:<input type="text" name="address">

<input type="submit" name="send" value="Send">

</form>

</center>

<% if(request.getMethod().equalsIgnoreCase("post"))

{ %>

<jsp:useBean id="app1" class="sample.Person1"/>

<jsp:setProperty name="app1" property="*"/>

Your number: <jsp:getProperty name="app1" property="number"/>

Your name: <jsp:getProperty name="app1" property="name1"/>

Your address: <jsp:getProperty name="app1" property="address"/>

Have a nice day

<% } %>

first when you request for a form.jsp, three text fields and a button of the

form gets displayed on the browser as a response to the client.

when the user enters the values and presses the send button, request will go to same jsp file as a POST request. So, IF condition

becomes true in this case becoz request is POST request.

in the IF loop, first statement

<jsp:useBean id="app1" class="sample.Person1"/>

when the JVM executes this line,it will check whether an object

of the specified bean class is already created. If it is already created,

reference is returned or a object of the bean class(Person1 here) is

created.

<jsp:setProperty name="app1" property="*"/>

so , now when the above line gets executed , the names of the text

fields in this application(here number,name1,address) will be checked with the variable names specified in the bean class. the names in the bean class i have taken are number,name1,address.

So the names are matched and the methods of bean class will be invoked and values will be set.

strictly_helpfula at 2007-7-13 23:18:04 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...