23. Explain about JSP Standard Action

* The use of JavaBeans within JSP pages is a system for accessing Java components through the standard interface of methods with set and get prefixes.
* The general syntax for the useBean tag is as follows.
<jsp:useBean id=”myBean” type=”classtype” class=”com.domain.ClassName” scope=”session” />

   #  The it attribute id mandatory and can be an arbitrary string, but each can only appear once within a page (i.e. You cannot have two beans with the same id within a page).
   #  The actual class must be stored under the WEB-INF\classes directory
   #  The scope attribute can be page,request,session, or application.
   #  The scope attribute is optional and if it is omitted the default is page scope.


# Java Bean Code

package com.wordpress.sharat;
public class TestJSPUseBean {
   private String firstName=”sharat”;
   private String lastName=”abcd”;
   public void setFirstName(String firstName) {
      this.firstName = firstName;
   public void setLastName(String lastName) {
      this.lastName = lastName;
   public String getFirstName() {
      return firstName;
   public String getLastName() {
      return lastName;

# Usage:

That JavaBean can be used within a JSP as follows
<jsp:useBean id=”testbean” type=”com.wordpress.sharat.TestJSPUseBean” class=”com.wordpress.sharat.TestJSPUseBean” scope=”session” />
# getProperty

<jsp:getProperty name=”testbean” property=”firstName”/>

name and property attributes are mandatory.
# setProperty

<jsp:setProperty name=”testbean” property=”firstName” value=”Donkey”/>

# This allows values of a JavaBean to be set at runtime.
# Param Attribute:
  It is a very common requirement to want to set a property according to a runtime query parameter.
  for example with the URL query string

  <jsp:setProperty name=”testbean” property=”firstName” param=”firstname” />
  <jsp:setProperty name=”testbean” property=”lastName”  param=”lastname” />

# Default Params:
  <jsp:setProperty name=”person” property=”*”   />
  then It will correctly map the firstName and lastName parameters to the “testbean” bean.

# type attribute in bean defication is optional. We can have a bean defication with type attribute and with out a “class” attribute.


2 Responses

  1. Hello,
    I am, James
    overall pretty good
    check out my site:


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: