Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Struts
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Struts Tag:

                         


bean:struts Tag -is used to create a new bean containing one of the standard Struts framework configuration objects. This tag retrieve the value of the specified Struts internal configuration object, and define it as a scripting variable.  Which is accessible as a  remainder of the current page and as a attribute of  page scope.

Note: Must specify exactly one of the

 

 

 

  1. formBean
  2. forward and
  3. mapping 
    Attributes to select the configuration object to be exposed
    ( If any type of  problem occurs while retrieving the specified configuration object then exception 
    will be thrown).
Name Description
id

This attribute specifies the name of the scripting variable (and associated page scope attribute) that will be made available with the value of the specified Struts internal configuration object.

formBean

The formBean attribute specifies the name of the Struts ActionFormBean definition object to be exposed.

forward

The forward attribute specifies the name of the global Struts ActionForward definition object to be exposed.

mapping

The mapping attribute specifies the matching path of the Struts ActionMapping definition object to be exposed.

Example Illustrating the use of the Struts<bean:struts> tag.
Here you will learn to use the Struts Html<bean:struts>tag. 
We will cover an example that will show a working of<bean:struts>tag.


Example code :
Creating an Action Class                                     
Develop a simple  action  class BeanStrutsAction.java .
package action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class BeanStrutsAction extends Action {
       private final static String SUCCESS = "success";
        public ActionForward execute(ActionMapping mapping, ActionForm  form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {        
        return mapping.findForward(SUCCESS);        
    }
}

Creating Form Bean  :

Develop a simple  Form Bean  class  BeanStrutsActionForm.java .

package actionForm;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class BeanStrutsActionForm extends
     
org.apache.struts.action.ActionForm{
    
    public BeanStrutsActionForm() {
        super();        
    }    
}

Defining form Bean in struts-config.xml file :
 Add the following entry in the struts-config.xml file for Form Bean.
 
<form-beans>
        <form-bean name="BeanStrutsActionForm" 
              type="actionForm.BeanStrutsActionForm"/>  
    </form-beans>

Developing the Action Mapping in the struts-config.xml   :
 <action input="/" name="BeanStrutsActionForm" path="/BeanStrutsAction" 
        scope=
"session" type="action.BeanStrutsAction" validate="false">

        <forward name="success"  path="/beanStrutsTag.jsp"/>

 </action>

Developing the beanStrutsTag.jsp page :
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body bgcolor="#999933">
        
        <h3><font color="#33FF33">bean:struts Tag Demo</font></h3>
        <bean:struts id="mapping" mapping="/BeanStrutsAction"/>
        <bean:struts id="fwd" forward="welcome"/>
        
        <TABLE BORDER="2">
            <TR>
                <Th><font color="#33FF33">Config Object Name</font></Th>
                <Th><font color="#33FF33">Config Object Value</font></Th>
            </TR>
            <TR>
                <TD><font color="#33FF33">mapping</font></TD>
                <TD><bean:write name="mapping"/></TD>
            </TR>
            <TR>
                <TD><font color="#33FF33">fwd</font></TD>
                <TD><bean:write name="fwd"/></TD>
            </TR>
        </TABLE>
        
    </body>
</html>
 

Add the following line in the index.jsp to call the form :
<a href="./BeanStrutsAction.do">beanStrutsTagDemo</a><br/> 
 


Building and Testing the Example:
Build , deploy and Test  the application . 
Open the browser and navigate to the
beanStrutsTag.jsp page
Your browser displays the following page
beanStrutsTag.jsp and see the output.

Output:



Above actions displays the working of <bean:struts>Tag.

              

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.