aspose file tools*
The moose likes JSP and the fly likes Question in getProperty Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Question in getProperty" Watch "Question in getProperty" New topic
Author

Question in getProperty

Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Can any one tell what's the main difference between the scope of
page and request in UseBean tag
When Iam working I don't find any difference ??


Regards,Vasantha<p>Great minds discuss ideas. Average minds discuss events. Small minds discuss people.
Java Brewer
Greenhorn

Joined: Oct 13, 2003
Posts: 5
Hi Sangeetha,

There is a definite difference. When using scope as page, the
bean instance will be available to the current page only.
Whereas when scope is request, and if you are using something
like <jsp:forward /> or RequestDispatcher.foward(req, res),
you can get the bean instance in the called JSP, and can
manipulate the object as desired in the called JSP.
I hope this is clear to you now.
Regards
Goodieguy
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Hi Goodieguy,
Can u give me an example for this !!
Here I have worked out like this .Can u say me is Iam correct
******************Mysite1.jsp**************************
<html>
<%@ page language="java" %>
<%@ page import="DMYInfo,Counters" %>
<jsp:useBean id="dmy" class="DMYInfo" scope="request/page" />
<jsp:setProperty name="dmy" property="Count" />
<jsp:getProperty name="dmy" property="Count" value="2" />
<jsp:forward page="mysite2.jsp" />
<form name="myform" method="post" action="mysite1.jsp">
<input type="submit">
</form>
</html>
*****************Mysite.jsp*************************
<html>
welcome here
<%@ page language="java" %>
<%@ page import="DMYInfo" %>
<jsp:useBean id="dmy" class="DMYInfo" />
<jsp:getProperty name="dmy" property="Count" />
</html>
***************DMYInfo classs
import java.io.*;
public class DMYInfo implements Serializable
{
private int count = 0;
public int getCount()
{
this.count++;
return this.count;
}
public void setCount(int count)
{
this.count = count;
}
}
*********************
either request or page scope is providing the same result.
can u tell what's wrong with my code

:roll: :roll: :roll:

Regards,
Sangeetha prabindh
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898


If you use this in the first JSP

and in the 2 nd jsp

The count will not be equal to 2.
If you change from page scope to requset you will see the change.
How did the below work?


The getProperty doed not have a value attribute?


Groovy
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Iam sorry it's my typing mistake.Can you please tell me when
no scope is mentioned in the <jsp:useBean ... which scope will be
taken as default
Regards,
Sangeetha Prabindh
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Originally posted by Sangeetha Helen:
Iam sorry it's my typing mistake.Can you please tell me when
no scope is mentioned in the <jsp:useBean ... which scope will be
taken as default
Regards,
Sangeetha Prabindh

page


I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Hi pradeep,
I have tried as what u said.But still I didn't get the proper result that
can clear my doubt.When I used request scope in the mysite2.jsp Iam
getting the same answer as the page scope.
can u help me out with some example
Regards,
Sangeetha Prabindh
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Originally posted by Sangeetha Helen:
Hi pradeep,
I have tried as what u said.But still I didn't get the proper result that
can clear my doubt.When I used request scope in the mysite2.jsp Iam
getting the same answer as the page scope.
can u help me out with some example
Regards,
Sangeetha Prabindh

Have you used the request scope in both the jsps?
JavaHunk
Greenhorn

Joined: Oct 16, 2003
Posts: 7
Hi Sangeeta,
Here is the modified JSP for you, You will get the correct result now


Ok you can change the scope of bean in Mysite1.jsp from
request to page, you will find the result
for request scope is 11 while for and page
scope is 1.

That clearly tells how scope works.
Regards
Goodieguy
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Thanks Goodieguy I could find the difference between page/request
but onething When I used for <jsp:forward... it is working
but when I used submit it is giving the count value as 1 why ???
Regards,
Sangeetha prabindh
Vasantha Prabha
Ranch Hand

Joined: Oct 02, 2003
Posts: 108
Thanks every one who helped me to understand the difference between these
to.But I still have the Question as what I mentioned above.
Regards,
Sangeetha Prabindh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question in getProperty
 
Similar Threads
Extending an EJB
jsp page performance (redundant taglib)
JATO Vs JDOM
using custom tags & tag handler class - URGENT
light weight& heavy weight