protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Person per2 = new Person("Request");
Person per3 = new Person("Session");
request.setAttribute("person", per2);
request.getSession().setAttribute("person", per3);
RequestDispatcher dispatcher = request.getRequestDispatcher("/test.jsp");
dispatcher.forward(request, response);
}
<jsp:useBean id="person" type="com.tridib.vo.Person" scope="session" />
<jsp:getProperty property="name" name="person"/>
package com.tridib.vo;
public class Person
{
private String name = "Tridib";
public Person()
{
}
public Person(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
Originally posted by Seenikkannan krishnasamy:
request.setAttribute("person",per2);
request.getSession().setAttribute("person",per3);
are you trying with same name "person"..isn't overwritten?
Originally posted by Seenikkannan krishnasamy:
i think useBean getProperty work like Pagecontext.findAttribute()..searches for the named attribute in page,request,session and application in order returns value associated or null;
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
-------------------------------------<br />SCJP<br />SCWCD
The value of the name attribute in jsp:setProperty and jsp:getProperty will
refer to an object that is obtained from the pageContext object through its findAttribute
method.
Originally posted by Clifton Eaton:
try specifying a different name. for example in your jsp:useBean tag, use an id of "sessionPerson" and then make the name in your jsp:getProperty tag match that.
Originally posted by Clifton Eaton:
The bottom line is that jsp:getProperty does not NEED the jsp:useBean because the named reference exists already and will be available in the fully compiled servlet.
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
The value of the name attribute in jsp:setProperty and jsp:getProperty will
refer to an object that is obtained from the pageContext object through its findAttribute
method.
Thanks, Tridib
SCJP 1.4, SCWCD 1.4, SCBCD 5.0
[My Blog]
All roads lead to JavaRanch
Originally posted by Satou kurinosuke:
getProperty finds the "person" in the request first, because the scope is not being set.
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |