Why do you use jsp:useBean?

Hi,
I have one "simple" question :) : When or why do you are using <jsp:useBean>,<jsp:getProperty> and <jsp:setProperty>?
For practice, I am creating a form, sends the data to a servlet and the servlet "packs" the parameter into a Bean and put this Bean into a request- or SessionScope. After that, my resultpage could access the property name of the bean with (for instance) sessionScope.Bean.name.
I wanted to use the 3 tags above first, but after I realised the way I describes above I didn't have to use these three jsp tags. Therefore I wonder when you are using these tags.
Thnx
Alex

hi
The component model for JSP technology is based on JavaBeans component architecture. JavaBeans components are nothing but Java objects which follow a well-defined design/naming pattern: the bean encapsulates its properties by declaring them private and provides public accessor (getter/setter) methods for reading and modifying their values.
Before you can access a bean within a JSP page, it is necessary to identify the bean and obtain a reference to it. The <jsp:useBean> tag tries to obtain a reference to an existing instance using the specified id and scope, as the bean may have been previously created and placed into the session or application scope from within a different JSP page. The bean is newly instantiated using the Java class name specified through the class attribute only if a reference was not obtained from the specified scope. Consider the tag:
sun site

Similar Messages

  • Which one better to use - jsp:useBean or import statement

    Hi,
    I just want to know that which one is better to use jsp:useBean or import statement .
    I can instantiate and call method of myclass -
    1) by importing the class through import tag in jsp as <%@page import="myclass"%. or
    2). by using <jsp:useBean tag....
    i have these two option to do the same thing. i know that basically useBean is used to call setter and getter method of bean class and but it can be used to call a normal java file that have some logic .
    so what should i used , which one is better and why?
    useBean provides scope and object instance so no need to create object by new operator. and with import you have to create an instance .
    but which tag should i use in my jsp?
    i am confused???

    ok, means i can use jsp:useBean tag for all my
    classes that are not actually bean. so it will be
    instantiated at run time and provide efficiency .No. Jsp:useBean is used for java bean components.
    >
    but when should i use import statement in my jsp and
    it happen at translation time so will it create any
    type of burden for my code if i import multiple
    classes.For non-java beans, you need to import the classes, period.
    It's not a burden, it's a necessity.

  • Why do we use jsp instead of servlet

    why do we use jsp instead of servlet

    Hi,
    I am and web/Java developer and have used a mixture of JSPs and servlets. I use JSPs for my actual web pages. Whether they are displaying dynamic database driven content or simple pages doing nothing but password protecting.
    I tend to separate other reusable code into servlets, like database connections and business logic.
    For example: I have worked on a mortgage site and there quite a lot that goes into calculating a monthly payment and ARP. These calculations will not change (only values I send to them will) therefore I do this type of coding in a servlet.
    Cheers
    Mark
    :o)

  • Unable to use jsp:useBean tag

    when I use
    <jsp:useBean id="addressBean" class="AddressBean" scope="session"/>
    I get the following error
    Exception Details: org.apache.jasper.JasperException
    Unable to compile class for JSP No Java compiler was found to compile the generated source for the JSP. This can usually be solved by copying manually $JAVA_HOME/lib/tools.jar from the JDK to the common/lib directory of the Tomcat server, followed by a Tomcat restart. If using an alternate Java compiler, please check its installation and access path.
    So my question is how to use the <jsp:useBean> tag in JSC

    Please see my message How to set developer's mode for oracle jsp engine.
    As a very early warning of the future, this way of setting configuration paramemter in web.xml for oracle jsp engine will be deprecated in the next major version of oc4j and desupported probably later on. Yes, it is still supported in 10.1.3 and the next major version, though.

  • Why do you use email to contact me but refuse to accept my email

    Hi
    I understand that email can be a very convenient and effective way of communication; however The FCC has strict regulations on how wireless carriers can ask and receive customer information.
    If you need assistance with an account or billing issue and you’re overseas you can always chat live or call our international support number free from your AT&T mobile at +1.916.843.4685.
    Thanks,
    Charise

    Why do I have to use Facebook, tweeter or this goofy community service instead of email? Why do you use my email address to contact me but refuse to accept email In return? Just like you, I also prefer the ease and convenience of email. Would you prefer I setup my own social network and require you to post your bills to it??! Email is ubiquitous and--unlike your service--it works perfectly overseas.

  • Why do YOU use Apple's Server product?

    So...I've been running 10.5 server for maybe 2 years. The services I use are: AFP SMB DHCP DNS Firewall Mail NAT Web VPN. I went from using linux (slackware no less) to using OS X Server. My issue here is....honestly it feels like OS X Server is a GUI wrapped around a closed source kernel and everything else open source. Paying $500 for something I could pretty much do myself is where I have an issue...and the fact that the admin gui is pretty limited. Even today I still have to manually edit natd to use ppp0 as an interface. I guess if people needed OD and all that jazz maybe it's worth it....so my question to all is the subject...why do YOU use it?

    AFP, mail, web - because AFP is the best choice in many instances for fileserving Mac OS X clients,
    and also (why OS X Server) because clients do not want to pay me what it actually takes to build it on my own, and I'm not going to do that for free for the "benefit" of not paying for it with my own time.
    What's provided is a pretty excellent base set of tools, and I can easily update clamav, amavisd-new and spamassassin manually which I'd be doing anyway on any other platform.
    As of 10.5, Postfix is a current enough version to do what I need, and I'm comfortable manually editing the config to get it to do all of what I want.
    I just don't have to spend ridiculous amounts of time building all of this,
    and with OS X (software and hardware) I get Target-disk mode, a far better GUI when I need it (not much), and the portability of a system drive is actually immeasurably better than I'm going to get with any other platform & OS out there. If you haven't experienced that yet then you don't know.
    Yes there are limits to that, but that's negligable compared to how thoroughly un-portable a system drive is anywhere else. To an extreme degree.
    NetBoot/NetInstall, asr, ease & portability of system images,
    The great benefit (OS X client) of commercial software (Adobe, Office, etc. ) alongside perl, python, ruby, shell scripting, etc.

  • Why use jsp:useBean?

    I got the below sample code in sun document. Here bookId is passed as a parameter in cart.remove method and sql query. I want to know why the statement "<jsp:useBean id="bookId" type="java.lang.String" /> " is used.
    <c:set var="bookId" value="${param.Remove}"/>
    <jsp:useBean id="bookId" type="java.lang.String" />
    <% cart.remove(bookId); %>
    <sql:query var="books"
    dataSource="${applicationScope.bookDS}">
    select * from PUBLIC.books where id = ?
    <sql:param value="${bookId}" />
    </sql:query>
    thanks,
    Vinodh

    The useBean tag has a side effect of creating a local scriptlet variable with the id "bookId"
    This variable is then used on the next line in the scriptlet code.
    In effect, it is executing the following code
    <c:set var="bookId" value="${param.Remove}"/>
    <%
    String bookId = (String)pageContext.findAttribute("bookId");
    cart.remove(bookId); %>which if you think about it, you could get rid of the <c:set> and have the scriptlet code access the variable directly.
    <%
    String bookId = request.getParameter("Remove");
    cart.remove(bookId); %>Mixing scriptlet and JSTL code in this fashion gets confusing.
    The scriptlet code here is part of the 1% of code that can't be replaced directly by JSTL (but could be replaced by a custom function/tag)
    However it more probably belongs in a servlet/bean.

  • Why do we need jsp:useBean???

    Hi All,
    I am going over both the J2EE tutorial and JSP1.2 spec.
    As far as I read, it seems to me that "jsp:useBean" is a way of creating a bean object.
    <jsp:useBean id="local" scope="application" class="Mylocales">
    If I put the class file in the import statement, can I create the object in the scriptlet
    <% Mylocales local = new Mylocales(); %>
    and set/get properties by calling
    local.setName(); // assume these methods are in the class
    local.getName();
    without using "jsp:setProperty" and "jsp:getProperty".In this way, isn't it a redundancy to have "jsp:useBean" in JSP spec? We can always create any kind of objects in the scriptlets.
    Since "jsp:useBean" has been there for years, I believe something must be wrong with my rationale. However, both the spec and the tutorial couldn't answer this question. Can anyone clear it up to me?
    Thx in advance.
    Kevin

    There's nothing wrong with your rationale; useBean IS a redundant tag, but it does provide some compact functionality without having to write extra code.
    http://java.sun.com/products/jsp/tags/11/syntaxref1115.html covers the syntax of this tag; one advantage of using this tag is the 'scope' attribute, that allows you to define, at object creation, just how long the object will be around. You can limit an object's scope to the page that declared it, or allow it to be accessed by any page that shares the same session, or request, or application.
    I do believe that the main point of this tag comes in at the design level; one of the strongest reasons to use JSPs at all is to separate out the application logic from the page presentation. This means that anyone who can use HTML should be able to maintain the JSP pages in the application. Instead of having to teach a non-programmer a little bit of code, just demonstrate the use of a single tag that can be reused throughout the application. The logical extension of this idea is the tag library.
    Myself, I mix and match as needed, but there are never more than a few lines of scriptlet code in my JSP pages. If there's more code than HTML in my JSP page, I'll go ahead and use a servlet instead.
    Anyway, I guess my point is that JSP pages are flexible, you can pick the functionality that you want to use, and the useBean tag isn't quite superfluous.

  • Why does people use JSP Tag for their JSP page? (Urgent)

    I don't know what benifit if I am using JSP Tag.
    If anyone knows, pls give me an idea and the advantage of using JSP Tag in JSP Page!
    Thanks in advance!

    You have to read a little about JSP, JSP stands for JavaServer Pages, you can use jsp tags and you can use java code. If you dont want to use jsp tags then you should just write html file, if you just want to use java, then write java class or a servlet.
    The need for jsp arised because people were inserting html code inside a servlet class..a big no no..and a headache. JSP separate model from the view...read a little about MVC-2 model view controller pattern.
    Also read some tutorial on this website...good luck
    K

  • Error trying to use jsp:useBean

              I am trying to use a class in a JSP that is basically a connection to an
              Oracle database. It works fine when used from a servlet. However, when I try
              to instantiate it from a JPS page, I get errors. Here is the snippet from
              the JSP page:
              <%@ page import="engr.projmgmt.*" %>
              <jsp:useBean id="OB" class="engr.projmgmt.OracleBroker" />
              The class is here:
              /usr/local/apache/servlets/engr/projmgmt/OracleBroker.class
              The weblogic class path contains /usr/local/apache/servlets.
              I get the following error in the weblogic log:
              Mon Aug 13 17:39:15 PDT 2001:<E> <ServletContext-General> Servlet failed
              with Exception
              java.lang.ClassNotFoundException: class engr.projmgmt.OracleBroker :
              java.lang.IllegalAccessException: engr/projmgmt/OracleBroker
              at java.beans.Beans.instantiate(Beans.java:215)
              at java.beans.Beans.instantiate(Beans.java:55)
              at jsp_servlet._PM._index._jspService(_index.java:90)
              at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :120)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:915)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:879)
              at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              Manager.java:269)
              at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
              at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              --------------- nested within: ------------------
              weblogic.utils.NestedRuntimeException: cannot instantiate
              'engr.projmgmt.OracleBroker' - with nested exception:
              [java.lang.ClassNotFoundException: class engr.projmgmt.OracleBroker :
              java.lang.IllegalAccessException: engr/projmgmt/OracleBroker]
              at jsp_servlet._PM._index._jspService(_index.java:92)
              at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              at
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              :120)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:915)
              at
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              l.java:879)
              at
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              Manager.java:269)
              at
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
              at
              weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              Anyone have anyideas?
              Thanks,
              CC
              

    I appears that your default constructor is not publicly accessible from the
              exception.
              Sam
              "Chuck Carson" <[email protected]> wrote in message
              news:[email protected]...
              >
              > I am trying to use a class in a JSP that is basically a connection to an
              > Oracle database. It works fine when used from a servlet. However, when I
              try
              > to instantiate it from a JPS page, I get errors. Here is the snippet from
              > the JSP page:
              >
              > <%@ page import="engr.projmgmt.*" %>
              > <jsp:useBean id="OB" class="engr.projmgmt.OracleBroker" />
              >
              > The class is here:
              > /usr/local/apache/servlets/engr/projmgmt/OracleBroker.class
              > The weblogic class path contains /usr/local/apache/servlets.
              >
              > I get the following error in the weblogic log:
              >
              > Mon Aug 13 17:39:15 PDT 2001:<E> <ServletContext-General> Servlet failed
              > with Exception
              > java.lang.ClassNotFoundException: class engr.projmgmt.OracleBroker :
              > java.lang.IllegalAccessException: engr/projmgmt/OracleBroker
              > at java.beans.Beans.instantiate(Beans.java:215)
              > at java.beans.Beans.instantiate(Beans.java:55)
              > at jsp_servlet._PM._index._jspService(_index.java:90)
              > at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              > at
              >
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              > :120)
              > at
              >
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:915)
              > at
              >
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:879)
              > at
              >
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              > Manager.java:269)
              > at
              >
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
              > at
              > weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              > --------------- nested within: ------------------
              > weblogic.utils.NestedRuntimeException: cannot instantiate
              > 'engr.projmgmt.OracleBroker' - with nested exception:
              > [java.lang.ClassNotFoundException: class engr.projmgmt.OracleBroker :
              > java.lang.IllegalAccessException: engr/projmgmt/OracleBroker]
              > at jsp_servlet._PM._index._jspService(_index.java:92)
              > at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
              > at
              >
              weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java
              > :120)
              > at
              >
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:915)
              > at
              >
              weblogic.servlet.internal.ServletContextImpl.invokeServlet(ServletContextImp
              > l.java:879)
              > at
              >
              weblogic.servlet.internal.ServletContextManager.invokeServlet(ServletContext
              > Manager.java:269)
              > at
              >
              weblogic.socket.MuxableSocketHTTP.invokeServlet(MuxableSocketHTTP.java:365)
              > at
              > weblogic.socket.MuxableSocketHTTP.execute(MuxableSocketHTTP.java:253)
              > at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:129)
              >
              >
              > Anyone have anyideas?
              >
              > Thanks,
              > CC
              >
              >
              

  • Why do you use air?

    Hi
    I am currently at uni writing a dissertation on creating desktop apps and in particular using Adobe air.  I was hoping I could get some views on it from the people who actually use it.  In particular why you use air as opposed to other development tools (ie titanium and silverlight)?  Also how easy do you find it to use?
    Would really appreciate any feedback I can get.  Thanks.

    Hi
    Thanks for the responses.  I am finishing the write up at the moment and it would be great if I could get some more feedback from developers, general thoughts on air would be good.
    Thanks

  • Why do you use Adobe Flash?

    I really just don't know a whole lot about Flash and so I'm curious why you each individually chose Flash over some other program. What kinds of things do you use it for?

    I've been using since September 2004 and I've been happy with it most of the time. Mostly because of the reason given above: fast package manager, stays out of my face, lets me handle stuff myself, easy to make your own packages, ...
    But lately my wishes / demands regarding a distro have changed: I don't have time anymore to do everything myself, nor to fix a borked system after a pacman -Syu. That's why I switched to Ubuntu on my company's laptop: stuff just has to work, I don't need the bleeding edge anymore. Mind you I didn't install vanilla Ubuntu: I used the alternate install CD and installed a "CLI system". This is very much like Arch: you end up with a minimal base system and you can decide for yourself where to go from there. So far I've been very pleased about Ubuntu.
    I still use Arch on my desktop and router. Although maybe I've become more of a Frugalware stable type of user, I can't let go of Arch as it's tought me a lot about Linux.

  • Why we should use JSP instead of Servlet ?

    I want to know what are the advantages to use JSP over Servlet.

    hi
    Servlets are server exctension ( like CGI ) separate executable
    modules to serve any request efficiently.
    Servlets are pure java classes, u can use them the write an html code to browser.
    u have to compile the servlet before u use it.
    JSP page, is a text-base document , u can type html inside it , and u can use java as scripting language, so it is more easy to use jsp rather than servlet as each jsp page is translated into a servlet by JSP engine.
    Hope this will help
    Good luck
    Mohammed

  • Why would you use Java over C/C++

    This thread :
    http://forum.java.sun.com/thread.jspa?threadID=689490
    Brought back to mind a problem I had in the first C program I worked on -
    I'd declared an array and a file pointer on the stack in a function, overwrote the end of the array by mistake, and trashed the file pointer. The file pointer was used a while after the array was overwritten - took me 2 days to work out what was happening. Array overwrites like this are just not possible in Java - that's a reason to use Java over C or C++.
    Anyone else got their own scare stories like this ? Maybe someone's got a Java scare story that would make you use C ?

    A C++ based bond trading system had the description database varchar field width of 60 characters. The GUI software to display this had buffers 60 characters wide. New bonds came along with widths of over 60 characters so the database field width was changed to 80 characters but nobody told us (the GUI maintenance team) about the change.
    There was no real problem for about 4 days after the first long named bond was inserted. Then, at random times, the GUI application would crash. It took many many days to find the source of the problem and to fix it. The blame was laid at the door of the GUI maintenance team even though we had not written the code and we had logged the potential problem in the bug database months before but management decided that it was not a problem so should not be 'fixed'.
    This literally cost millions because the traders could not be sure of their positions.
    I left as soon as my contract ran out.

  • Why would you use a managed service account rather than a virtual account in SQL Server 2012?

    In SQL Server 2012, service accounts are created as
    virtual accounts (VAs), as described
    here, as opposed to
    managed service accounts (MSAs).
    The important differences I can see for these, based on the descriptions:
    MSAs are domain accounts, VAs are local accounts
    MSAs use automagic password management handled by AD, VAs have no passwords
    in a Kerberos context, MSAs register SPNs automatically, VAs do not
    Are there any other differences? If Kerberos is not in use, why would a DBA ever prefer an MSA?
    UPDATE:
    Another user has noted a
    possible contradiction in the MS docs concerning VAs:
    The virtual account is auto-managed, and the virtual account can access the network
    in a domain environment.
    versus
    Virtual accounts cannot be authenticated to a remote location. All virtual accounts
    use the permission of machine account. Provision the machine account in the format
    <domain_name>\<computer_name>$.
    What is the "machine account"? How/when/why does it get "provisioned"? What is the difference between "accessing the network in a domain environment" and "authenticating to a remote location [in a domain environment]"?

    Hi,
    “Virtual accounts cannot be authenticated to a remote location. All virtual accounts use the permission of machine account. Provision the machine account in the format <domain_name>\<computer_name>$.”
    “The virtual account is auto-managed, and the virtual account can access the network in a domain environment. If the default value is used for the service accounts during SQL Server setup on Windows Server 2008 R2 or Windows 7, a virtual account
    using the instance name as the service name is used, in the format NT SERVICE\<SERVICENAME>”
    Per the above description, they are two concepts and not conflict with each other.
    As you understand, virtual account access network resources by using the credentials of the computer account. Generally, computer account will not be granted permission unless giving the computer account permission on the shared folder manually.
    Thanks.
    Tracy Cai
    TechNet Community Support

Maybe you are looking for

  • Error - E 036 No goods receipt possible for purchase order

    Good Day, Am not able to do the Goods Receipt through BAPI : BAPI_GOODSMVT_CREATE.But am able to create GR through MIGO.Am getting the below error through BAPI: E 036 No goods receipt possible for purchase order  4500000563 0010. I gone throug the SD

  • IMovie searching for files for project that does not exist...

    Whenever I fire up iMovie 09 on Lion, it spins, and then tells me it can't find a video file for a project that does not exist. That is, it says 'File xxx.mov from project 'Movie 1 cannot be found - without this file the movie cannot be played.' The

  • Transparent integration of a new drive into the folder structure of a file server?

    Hallo, I'm looking for solution to a problem, that seams to be simple, but obviously is not that easy to solve: I have to integrate a second external RAID system in to our MacOS X 10.6.8 Server based file sharing server that is accessed from Mac and

  • Copley Xenus Drive with PXI-8461

    Hello, I am trying to learn how to use the Copley Xenus drive with Copley's CMO library in LabVIEW. I'm struggling with finding a starting point. I'm new to using .NET framework and it seems like there should be an easier way to talk to the drive wit

  • TS1389 Ehhh... Removing the SC Info Folder with Windows 8???

    I have Windows 8 and have just updated iTunes to the latest version. Now I get error -42110 when opening iTunes and I can see from troubleshooting that I have to remove the SC info folder (whatever that is??) but there are no directions on how to do