• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question in getProperty

 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Java Brewer
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Vasantha Prabha
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic