[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

<jsp:usebean> question

Posted on 2003-10-30
7
Medium Priority
?
883 Views
Last Modified: 2006-11-17
we have <%@useBean id = "myBean" class = "com.junk.MyBeanClass" scope = "page">  
in a jsp called "MyFirstJSP.jsp"

This is equilaent to
<%
MyClassBean myBean = new MyClassBean();
%>

My question is in the scope attribute.

page "the bean is there as long as the page is active"
---> Does this mean the scope of the object is throughout the page and when the user moves from the page the object is not avaioable

request "the bean is avaialbale for the target of the page ..."
--->is the scope avaibale for the request , which means if the page is forward to nect page , i need not create a new object but use the existing object

session "the bean is accesibke from any jsp page participate in the session"
---> I can use the objecy anywhere i want in all the pages for that particular session. ie I can load user info such as name , login , passowrd in a bean and call it anywhere without making a new object in each page.

ie in MySecondJSP.jsp I can use  "myBean.getInfo() " without ceating the obejct in the second page

appication "the bean ia avaibale throuhg the appication"
---> I can call the object of the bean anywhere i want an example is to store some name values pais similar to servelt context.

Thx for ur help :)

0
Comment
Question by:applekanna
7 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 9656162
Well,
You have pretty much answered your own question in the question inself....!! whats there for us to add??
0
 
LVL 15

Accepted Solution

by:
jimmack earned 200 total points
ID: 9656713
page - yes
request - yes
session - yes
application - yes (application isn't *similar* to servlet context, it *is* servlet context)

;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9657032
-- This is equilaent to
-- <%
--   MyClassBean myBean = new MyClassBean();
-- %>

Not quite...  It's equivalent to:

<%
   MyClassBean myBean = new MyClassBean();
   pageContext.setAttribute( "myBean", myBean );
%>
 
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 15

Expert Comment

by:jimmack
ID: 9657439
Good catch Tim ;-)
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9657447
;-)
0
 
LVL 3

Author Comment

by:applekanna
ID: 9658894
Hmm..

In my app, I have user info , contact info and other info as session beans and get them in each page. SO I can now replace them with javs use bean .

How is it advantageous - session attributes and/or  use bean

Thanks.
0
 
LVL 28

Expert Comment

by:rrz
ID: 9661647
>How is it advantageous - session attributes and/or  use bean
They are the same.
If in JSP you have the following  

      <jsp:useBean id="greeting" class="java.lang.String"/>
      <% greeting = "hello"; %>
      <%=greeting%>    

then Tomcat will translate it  to the following. (look in Tomcat's work folder)


   java.lang.String greeting = null;
synchronized (pageContext) {
    greeting = (java.lang.String) pageContext.getAttribute("greeting", PageContext.PAGE_SCOPE);
    if (greeting == null){
    try {
         greeting = (java.lang.String) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "java.lang.String");
        } catch (ClassNotFoundException exc) {
            throw new InstantiationException(exc.getMessage());
        } catch (Exception exc) {
            throw new ServletException("Cannot create bean of class " + "java.lang.String", exc);
        }
          pageContext.setAttribute("greeting", greeting, PageContext.PAGE_SCOPE);
        }
}
out.write("\r\n");
greeting = "hello";       out.write(" \r\n");
out.print(greeting);
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
Tech giants such as Amazon and Google have sold Alexa and Echo to such an extent that they have become household names. And soon they are expected to be used by commoners in their homes, ordering takeout, picking out a song, answering trivia questio…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question