JSP tags

Posted on 2006-06-06
Last Modified: 2013-11-24

What is the jsp:useBean class id and scope used for?

What is the jsp:setProperty name property and param for too?

Question by:jedistar
    LVL 86

    Expert Comment

    LVL 3

    Expert Comment

    LVL 10

    Accepted Solution

    <jsp:useBean class = "ClassName" ID = "instanceName" >

    is equivalent to your java code

      ClassName instanceName = new ClassName ();

    you can reference the instanceName Object in ur jsp according to the scope u give.

    <jsp:setProperty name = "instanceName" property = "beanProperty" param = "data1">

    is equivalent to calling the setBeanProperty method as shown below,
    instanceName.setbeanProperty ( data1 );

    similarly jsp:getProperty  tag is used to access the properties of the bean
    LVL 10

    Expert Comment

    supose u ve a customer bean say
    Customer { name,  age, address } with all getters and setters for that.

    you have a html form contining all the fields of customer in that. when you submit it to your jsp, the JSP can map the input paramters ( form values ) directly to the bean using these tags.

    suppose if your form fields also have the same names as of customer ( name,age,address )

    you can call

       <jsp:useBean class = "Customer" ID = "customer" >
      <jsp:setPropert name = "customer" property = "*" />

    the tags above will create a beanInstance customer and name,age,address are set to the values as specified in the form.

    LVL 10

    Expert Comment

    Forgot to mention the SCOPE .

    it can be page,request or session

    if its page scope then the bean will be available only in that page
    if it is request scope then the bean will be available only in the request
    if it is session scope then the bean is available throught the session.

    the default scope is page scope

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    746 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now