Question about main difference between Java bean and Java class in JSP

Hi All,
I am new to Java Bean and wonder what is the main difference to use a Bean or an Object in the jsp. I have search on the forum and find some post also asking the question but still answer my doubt. Indeed, what is the real advantage of using bean in jsp.
Let me give an example to illustrate my question:
<code>
<%@ page errorPage="errorpage.jsp" %>
<%@ page import="ShoppingCart" %>
<!-- Instantiate the Counter bean with an id of "counter" -->
<jsp:useBean id="cart" scope="session" class="ShoppingCart" />
<html>
<head><title>Shopping Cart</title></head>
<body bgcolor="#FFFFFF">
Your cart's ID is: <%=cart.getId()%>.
</body>
<html>
</code>
In the above code, I can also create a object of ShoppingCart by new operator then get the id at the following way.
<code>
<%
ShoppingCart cart = new ShoppingCart();
out.println(cart.getId());
%>
</code>
Now my question is what is the difference between the two method? As in my mind, a normal class can also have it setter and getter methods for its properties. But someone may say that, there is a scope="session", which can be declared in an normal object. It may be a point but it can be easily solved but putting the object in session by "session.setAttribute("cart", cart)".
I have been searching on this issue on the internet for a long time and most of them just say someting like "persistance of state", "bean follow some conventions of naming", "bean must implement ser" and so on. All of above can be solved by other means, for example, a normal class can also follow the convention. I am really get confused with it, and really want to know what is the main point(s) of using the java bean.
Any help will be highly apprecaited. Thanks!!!
Best Regards,
Alex

Hi All,
I am new to Java Bean and wonder what is the main
difference to use a Bean or an Object in the jsp. The first thing to realize is that JavaBeans are just Plain Old Java Objects (POJOs) that follow a specific set of semantics (get/set methods, etc...). So what is the difference between a Bean and an Object? Nothing.
<jsp:useBean id="cart" scope="session" class="ShoppingCart" />
In the above code, I can also create a object of
ShoppingCart by new operator then get the id at the
following way.
ShoppingCart cart = new ShoppingCart();
out.println(cart.getId());
...Sure you could. And if the Cart was in a package (it has to be) you also need to put an import statement in. Oh, and to make sure the object is accessable in the same scope, you have to put it into the PageContext scope. And to totally equal, you first check to see if that object already exists in scope. So to get the equivalant of this:
<jsp:useBean id="cart" class="my.pack.ShoppingCart"/>Then your scriptlet looks like this:
<%@ page import="my.pack.ShoppingCart %>
<%
  ShoppingCart cart = pageContext.getAttribute("cart");
  if (cart == null) {
    cart = new ShoppingCart();
    pageContext.setAttribute("cart", cart);
%>So it is a lot more work.
As in my mind, a normal class can also
have it setter and getter methods for its properties.True ... See below.
But someone may say that, there is a scope="session",
which can be declared in an normal object.As long as the object is serializeable, yes.
It may be
a point but it can be easily solved but putting the
object in session by "session.setAttribute("cart",
cart)".Possible, but if the object isn't serializable it can be unsafe. As the point I mentioned above, the useBean tag allows you to check if the bean exists already, and use that, or make a new one if it does not yet exist in one line. A lot easier than the code you need to use otherwise.
I have been searching on this issue on the internet
for a long time and most of them just say someting
like "persistance of state", "bean follow some
conventions of naming", "bean must implement ser" and
so on. Right, that would go along the lines of the definition of what a JavaBean is.
All of above can be solved by other means, for
example, a normal class can also follow the
convention. And if it does - then it is a JavaBean! A JavaBean is any Object whose class definition would include all of the following:
1) A public, no-argument constructor
2) Implements Serializeable
3) Properties are revealed through public mutator methods (void return type, start with 'set' have a single Object parameter list) and public accessor methods (Object return type, void parameter list, begin with 'get').
4) Contain any necessary event handling methods. Depending on the purpose of the bean, you may include event handlers for when the properties change.
I am really get confused with it, and
really want to know what is the main point(s) of
using the java bean.JavaBeans are normal objects that follow these conventions. Because they do, then you can access them through simplified means. For example, One way of having an object in session that contains data I want to print our might be:
<%@ page import="my.pack.ShoppingCart %>
<%
  ShoppingCart cart = session.getAttribute("cart");
  if (cart == null) {
    cart = new ShoppingCart();
    session.setAttribute("cart", cart);
%>Then later where I want to print a total:
<% out.print(cart.getTotal() %>Or, if the cart is a JavaBean I could do this:
<jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session"/>
Then later on:
<jsp:getProperty name="cart" property="total"/>
Or perhaps I want to set some properties on the object that I get off of the URL's parameter group. I could do this:
<%
  ShoppingCart cart = session.getAttribute("cart");
  if (cart == null) {
    cart = new ShoppingCart();
    cart.setCreditCard(request.getParameter("creditCard"));
    cart.setFirstName(request.getParameter("firstName"));
    cart.setLastName(request.getParameter("lastName"));
    cart.setBillingAddress1(request.getParameter("billingAddress1"));
    cart.setBillingAddress2(request.getParameter("billingAddress2"));
    cart.setZipCode(request.getParameter("zipCode"));
    cart.setRegion(request.getParameter("region"));
    cart.setCountry(request.getParameter("country"));
    pageContext.setAttribute("cart", cart);
    session.setAttribute("cart", cart);
  }Or you could use:
<jsp:useBean id="cart" class="my.pack.ShoppingCart" scope="session">
  <jsp:setProperty name="cart" property="*"/>
</jsp:useBean>The second seems easier to me.
It also allows you to use your objects in more varied cases - for example, JSTL (the standard tag libraries) and EL (expression language) only work with JavaBeans (objects that follow the JavaBeans conventions) because they expect objects to have the no-arg constuctor, and properties accessed/changed via getXXX and setXXX methods.
>
Any help will be highly apprecaited. Thanks!!!
Best Regards,
Alex

Similar Messages

  • Question about Hz difference between MacBook Pro and iMac?

    Some will think I'm crazy for saying this, but my new MacBook is driving me nuts.
    In a nutshell, I have tinnitus as a result of an accident some years ago. I can hear an intermittent high pitch sound coming from the back left of the machine. I used to hear a similar sound from old TVs back when I first got tinnitus. After some deduction I realised that it was to do (I think) with the fequency. I sold my old TV and brought a new one that was a 100Hz. My theory was somewhat confirmed when they delivered it and it was the 50Hz version and yes, the high pitch sound was very evident! Upon receipt of the 100Hz model and I immediately noticed the difference.
    I'm guessing then that the MacBook has something inside emitting 50-60Hz - someone on this forum mentioned that too.
    Although I want the portability, I can't stand that sound all day long, so I'm thinking of taking it back and swapping it for an iMac.
    The question is, will I find the same problem? I'm not sure of the technical specifications in terms of Hz's between the two machines.
    It's too noisy in the shop to tell.
    Any advice appreciated.
    PS - did not have this issue with my 2008 MacBook pro.
    PPS - makes no difference if it's plugged in or not.

    Isolating the source of the high frequency would take a technician with the instruments to deteermine what components emit sound...actually very easy to do with the proper test instruments, but essential to tell you what is causing the offending sound.  Unless you know that it will be very hard to determine if the iMac will not do the same thing.
    Only qualitative way to find out is go to an Apple store or reseller with a good selection of hardware, work with the different hardware and see if it bothers you.  Preferably with few people around and low background noise level so the sound isn't masked.

  • What are the main differences between Signal Express and Labview?

    National Instruments provides a matrix so one can quickly compare the
    various versions of Labview but no comparison of Signal Express with
    Labview. Hence how does Signal Express compare with Labview? What
    are some of the things one can do with Labview one can't do with
    Signal Express?
    Howard

    hrh1818 wrote: Which version of Labview are you referring to? I don't consider the graphical version of Labview to be a full featured programming language. LabWindows/CVI is by a long shot a lot closer to being a full featured programming language than the graphical version of Labview.
    Howard,
    You clearly don't know what you are talking about. There is no "graphical version" of LabVIEW, there is just LabVIEW. Click on the article "Is LabVIEW a general purpose programming language?" written by the Jeff K. for some easy reading from a few years ago. It is all still true (except that object oriented features and recursion have been added in recent versions).
    One of the main points at this years NI-week was the discussion of how processor development is switching more and more to multicore designs  to improve performance because a simple boost in clock frequency is becoming more difficult. Linear, text based code is not well suited to take advantage of multticore design, while the dataflow based LabVIEW programming language automatically scales well to multiple processor cores, without any need to rewrite older code. I would say that only LabVIEW is futureproof in this respect. LabVIEW programmers are not wimps that are simply too stupid to write text based code. LabVIEW is not a toy language for people that don't want to learn a "real" programming language.
    LabVIEW is arguably the best programming language in terms of getting things done! I've never felt limited with LabVIEW and my programs often don't even have anything to do with data acquisition or instrument control. The difference between text based code vs. LabVIEW is like "DOS vs. Windows", "Radio vs. HD television". "Trilobyte vs. Homo sapiens" (sorry Putnam ). Text based code is monochrome, archaic and outdated and its linearity imposes unecessary constraints on the programmer that can only be (partially) overcome by wasting even more time throwing even more code at it.
    Sure, a seasoned text based programmer will initially have problems adapting to LabVIEW, just because you would need to adapt to and embrace the power of dataflow and not try to make a literal translation of the text code to LabVIEW, retaining old habits. If you get stuck, come back and ask here in the forum.
    You were looking for object oriented features and failed. All you need to do is a quick site search. All the information is out there. Just because you cannot find it in the first five sentences of the glossy brochure does not mean it does not exist. Maybe you want to read one of the application notes such as:
    LabVIEW Object-Oriented Programming: The Decisions Behind the Design
    In general, you should avoid judgement until you have all information. Your opinions seem quite biased and superficial and not really based on hard facts.
    Initially you asked about the difference between signal express and LabVIEW.
    hrh1818 wrote:
    > What kind of measurments do you want to do and what kind of requirements do you have?
    > You can also see for yourself and download evaluation version of both.
    No thanks, there has to be a better way to get an answer to my
    question than get involved in a two month study project.
    If you would answer the first question quoted above, we could certainly help you with the decision. Isn't that the main purpose of this thread?
    You can also contact your local LabVIEW Field Engineer to go over your requirements and help you make a decision. They usually know their stuff!
    Message Edited by altenbach on 09-02-2007 11:51 PM
    LabVIEW Champion . Do more with less code and in less time .

  • What is difference between Managed Bean and Backing Bean?

    What is difference between Managed Bean and Backing Bean? Please guide me how to create them and when to use them?
    Please post sample for both beans.

    Hi,
    managed beans and backing beans are quite the same in that the Java object is managed by the JavaServer Faces framework. Manage in this respect means instantiation. The difference is that backing beans contain component "binding" references, which managed beans usually don't. Do backing beans are page specific versions of managed beans.
    Managed beans are configured either in the faces-config.xml file, or using ADF Faces and ADFc, in the adfc-config.xml file
    Frank
    Edited by: Frank Nimphius on Jan 31, 2011 8:49 AM

  • Can anyone explain the main differences between CRM 2007 and CRM 7?.

    Can anyone explain the main differences between CRM 2007 and CRM 7?.
    Does CRM 2007 use the WebUI?.
    Jason

    My fault for not putting my question forward correctly.
    I have worked with CRM 7 a few times now, but my experience has jumped me from CRM 5 straight to CRM 7, having never touched CRM 2007.
    I now have an opening to work on CRM 2007 so I was intrigued to know what it physically looked like. I assume it does not use the WebUI interface?.
    Jas

  • Regarding main difference between  Enhancement point and section

    Hello,
    Actually Iam new to Abap ,I would like to know the main difference between Enhancement point and section, so can you please give a brief clarification.
    Thanks & regards,
    Raju.
    Moderator message: Welcome to SCN!
    Moderator message: please search for available information/documentation.
    [Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
    [Asking Good Questions in the Forums to get Good Answers|Asking Good Questions in the SCN Discussion Spaces will help you get Good Answers]
    Edited by: Thomas Zloch on Feb 5, 2012 8:59 AM

    Hi Raju,
    Please see the article below. He will help you:
    [Introducing the Enhancement Framework: The Cool New Way to Enhance Your ABAP Systems|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/bb54c452-0801-0010-0e84-a653307fc6fc]
    Regards,
    Bruno Xavier.

  • What is the main difference between f.13 and f13e

    Hi,
       What is the main difference between f.13 and f13e.
      when clearing the document do they follow deifferent steps in selection?
    Thanks,
    Sravanthi

    Hi,
    The reason "Clearing currency" is provided is because you can clear in any currency apart from local currency. For eg if your local currency is INR and Document currency (Invoice) is USD and the customer pays in EUR, you can still clear them with the Clearing currency EUR. On the date of payment, Open items in USD will be converted into Clearing currency EUR as follows: USD to INR and from INR to EUR. (based on exchange rates between USD-INR and INR-EUR).
    Jayaram

  • What are the main differences between airport express and extreme?

    what are the main differences between the express and extreme base stations.

    In addition to Bob Timmons' link the main differences are as follows:
    Extreme has a slightly more powerful antenna (might not be true but from experience it seems to be)
    Extreme has USB HDD sharing
    Express has AirPlay
    Extreme has 3 Gigabit ports (don't be confused by Apple's page. Apple states 4 including WAN, 3 without WAN)
    Express is smaller
    Express has 10/100 Ethernet whereas Extreme has Gigabit

  • About the Differences between MyServices Professional and MyServices Consumer

    About the Differences between MyServices Professional and MyServices Consumer
    MyServices Professional is different from MyServices Consumer in the following ways:
    There are Common Tasks links on the home page for Order on Behalf and for Authorizations (if the Authorization portlet is enabled in the user's profile).
    Automatically grants the Order on Behalf permission for all people in the Home OU of the MyServices Professional user.
    Adds the "Authorizations for Others" view on the Authorizations page. This view allows the MyServices Professional user to view -- but not perform -- all Authorizations for people in their Home OU.
    See the attached file for more detail and screenshots of: MyServices Consumer with and without the Order on Behalf link displayed, and Requisition and Authorization list views; MyServices Professional Home page with and without the Authorizations portlet visible, and Requisition and Authorization list views. 
    Note: RequestCenter 2006 cannot be configured to automatically add users to MyServices Professional on creation of their user record via directory integration. This can be accomplished in RC2007, since roles can be imported from LDAP in that version.

    Hi Koji,
    One thing to consider is the number of different source types. BO supports SAP and all the relational DBs. There is also the fact that BO provides a single front end to different reporting type which makes the user experience much better. Finally, users ability to build there own reports, without a high level of traiining is one of the big selling points for BO.
    Here is a good overview  of the combination of the 2 , including some roadmap
    https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10c3bca6-7dbc-2a10-7aa8-81d2731c7bb1
    Hope this helps
    Alan

  • Whats the difference between an INTERFACE and a CLASS?

    Whats the difference between an INTERFACE and a CLASS?
    Please help.
    Thanx.

    http://search.java.sun.com/search/java/index.jsp?col=javaforums&qp=%2Bforum%3A31&qt=Difference+between+interface+and+class

  • JAVA beans and JAVA related services require Oracle client to be installed?

    Can you please advice whether an application server that make use of JAVA beans and JAVA related services require Oracle client to be installed? For an example if the solution build based on Java and JBOSS to be used as application server, do we still require oracle client to be installed and configure the tnsnames in order to communicate to database server?

    SHANOJ wrote:
    Can you please advice whether an application server that make use of JAVA beans and JAVA related services require Oracle client to be installed? For an example if the solution build based on Java and JBOSS to be used as application server, do we still require oracle client to be installed and configure the tnsnames in order to communicate to database server?Oracle client is not required when JDBC is used to connect to the remote DB

  • Is there any difference between java Beans and general class library?

    Hello,
    I know a Java Bean is just a java object. But also a general class instance is also a java object. So can you tell me difference between a java bean and a general class instance? Or are the two just the same?
    I assume a certain class is ("abc.class")
    Second question is is it correct that we must only use the tag <jsp:useBean id="obj" class="abc.class" scope="page" /> when we are writng jsp program which engage in using a class?Any other way to use a class( create object)? such as use the java keyword "new" inside jsp program?
    JohnWen604
    19-July-2005

    a bean is a Java class, but a Java class does not have to be a bean. In other words a bean in a specific Java class and has rules that have to be followed before you have a bean--like a no argument constructor. There are many other features of beans that you may implement if you so choose, but read over the bean tutorial and you'll see, there is a lot to a bean that is just not there for many of the Java classes.
    Second question: I'll defer to someone else, I do way to little JSP's to be able to say "must only[\b]".

  • Difference between BI Beans and olap api

    HI
    is there anyone can tell me the difference between
    BI and olap api ,
    is BI a language or components ,why
    when i build crosstab with BI beans it uses classes
    different from olap pi classes (oracle.dss.*)
    and olap api (oracle.express.*)
    so BI is another language independent of olap api
    or it uses olap api to connect to OLAP
    BI works , OLAP api doesn't work
    thanks

    Hi,
    This is a great question. The OLAP API is an Oracle published Java API for access to Oracle OLAP. This exposes the OLAP cube/dimension model via Java. The OLAP API documentation can be found on the OLAP secion of OTN, see the link on the BI Beans section of OTN. Within the documention section there is a link to the acle9i OLAP Release 2 - Developer's Guide to the OLAP API:
    http://otn.oracle.com/products/bi/pdf/OLAPIguide.pdf
    Customers can write their own Java code directly against this public API to display and manage OLAP objects. The OLAP API documentation explains how to do this.
    As users typically will want to present OLAP data in either a crosstab and/or graph Oracle created a pre-packaged set of components to help customers to quickly and easily create powerful OLAP applications. BI Beans are a set of fully J2EE compliant java beans that provide major components such as:
    - presentation beans (graph/crosstab/table)
    - OLAP beans
    - catalog services beans
    These components have extensive APIs to allow developers to comprehensively customize an application, both Java client and thin client (HTML/JSP and UIX).
    By default BI Beans connect to an Oracle database using the OLAP API as a primary data source (although users can create their own non-OLAP data sources). This allows developers and end-users to directly access dimensions and measures created to the OLAP specification.
    This is explained in more detail in the Oracle BI Beans Technical Whitepaper:
    http://otn.oracle.com/products/bib/htdocs/collateral/bi_beans_white_paper.pdf
    Hope this helps
    Business Intelligence Beans Product Management Team
    Oracle Corporation

  • The Question about stock transfer between HU-Management and WM-Management

    Hi,
    There is a scenario about stock transfer between HU-Management and WM-Management storage location. I use transaction MB1B , movement type 313 , 315. After Good issue from WM-management storage location, outbound delivery will genarated, then Pack, Create/Confirm TO, at last post goods issue for the outboud delivery. But when i do movement type 315, there is a warning message "Data of preceding document was not transmitted", and from the F1 help i find this system reponse "You can maintain an indicator that makes information about preceding documents in this delivery available under delivery type in Customizing. For some characteristics of this indicator, the type of preceding document and the related document and item numbers must be transmitted to delivery creation. At least one of these parameters is missing.".
    So, My questions are:
    1. Generallily, Outbound delivery is created by SO, inbound delivery is created referenc PO, but how the stock transfer for 2 steps generate the outbould delivery and inbound delivery? Could you pls tell me the where i can config this in the IMG?
    2. What's "Data of preceding document was not transmitted" mean ? how to fix this issue ?
    Best Regards
    Boxer Du
    I am the SAP fans, focus on MM and WM. I am interesting TRM Yard Management and Cross Docking now.Very Gladly to talk you about these areas. I want to exchange the knowledge with you, and want to be a good friend of you. Pls contact me. You can find My MSN in the profile. Thanks.

    Hi,
    Sure, The inbound delivery type is set up in the IMG->Logistics General -> HU management -> Basics ->Delivery type -> Delivery type determination.
    For Inbound delivery type 'HID' is maintained in this view.
    Best Regards.
    Some One want to discuss the details , can contact me. Thanks.

  • Main difference between 4.6c and ecc 5.0

    Hi,
    Please give  me brief about difference between 4.6c and ECC 5.0
    Thanks,
    Asha

    Hi Asha,
                 you can see in Tcode : UCCHECK .you modify the objects in unicode conversion.some functionality didn't support in ECC 5.0.
    this is the brief documentation of that TCODE.
    BAP Unicode Scan Tool UCCHECK
    You can use transaction UCCHECK  to examine a Unicode program set for syntax errors without having to set the program attribute "Unicode checks active" for every individual program. From the list of Unicode syntax errors, you can go directly to the affected programs and remove the errors. It is also possible to automatically create transport requests and set the Unicode program attribute for a program set.
    Some application-specific checks, which draw your attention to program points that are not Unicode-compatible, are also integrated.
    Selection of Objects:
    The program objects can be selected according to object name, object type, author (TADIR), package, and original system. For the Unicode syntax check, only object types for which an independent syntax check can be carried out are appropriate. The following object types are possibilities:
    PROG Report
    CLAS Class
    FUGR Function groups
    FUGX Function group (with customer include, customer area)
    FUGS Function group (with customer include, SAP area)
    LDBA Logical Database
    CNTX Context
    TYPE Type pool
    INTF Interface
    Only Examine Programs with Non-Activated Unicode Flag
    By default, the system only displays program objects that have not yet set the Unicode attribute. If you want to use UCCHECK to process program objects that have already set the attribute, you can deactivate this option.
    Only Objects with TADIR Entry
    By default, the system only displays program objects with a TADIR entry. If you want to examine programs that don't have a TADIR entry, for example locally generated programs without a package, you can deactivate this option.
    Exclude Packages $*
    By default, the system does not display program objects that are in a local, non-transportable package. If you want to examine programs that are in such a package, you can deactivate this option.
    Display Modified SAP Programs Also
    By default, SAP programs are not checked in customer systems. If you also want to check SAP programs that were modified in a customer system (see transaction SE95), you can activate this option.
    Maximum Number of Programs:
    To avoid timeouts or unexpectedly long waiting times, the maximum number of program objects is preset to 50. If you want to examine more objects, you must increase the maximum number or run a SAMT scan (general program set processing). The latter also has the advantage that the data is stored persistently. Proceed as follows:
    - Call transaction SAMT
    - Create task with program RSUNISCAN_FINAL, subroutine SAMT_SEARCH
    For further information refer to documentation for transaction SAMT.
    Displaying Points that Cannot Be Analyzed Statically
    If you choose this option, you get an overview of the program points, where a static check for Unicode syntax errors is not possible. This can be the case if, for example, parameters or field symbols are not typed or you are accessing a field or structure with variable length/offset. At these points the system only tests at runtime whether the code is sufficient for the stricter Unicode tests. If possible, you should assign types to the variables used, otherwise you must check runtime behavior after the Unicode attribute has been set.
    To be able to differentiate between your own and foreign code (for example when using standard includes or generated includes), there is a selection option for the includes to be displayed. By default, the system excludes the standard includes of the view maintenance LSVIM* from the display, because they cause a large number of messages that are not relevant for the Unicode conversion. It is recommended that you also exclude the generated function group-specific includes of the view maintenance (usually L<function group name>F00 and L<function group name>I00) from the display.
    Similarly to the process in the extended syntax check, you can hide the warning using the pseudo comment ("#EC *).
    Applikation-Specific Checks
    These checks indicate program points that represent a public interface but are not Unicode-compatible. Under Unicode, the corresponding interfaces change according to the referenced documentation and must be adapted appropriately.
    View Maintenance
    Parts of the view maintenance generated in older releases are not Unicode-compatible. The relevant parts can be regenerated with a service report.
    UPLOAD/DOWNLOAD
    The function modules UPLOAD, DOWNLOAD or WS_UPLOAD and WS_DOWNLOAD are obsolete and cannot run under Unicode. Refer to the documentation for these modules to find out which routines serve as replacements.
    cheers,
    sekhar.

Maybe you are looking for