Services | Updates | Contact
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
Get first day of week
In this section, we will learn how to get the first day of week in Java. As we know that GregorianCalendar provides the
 
Convert Hexa To Char
In this example, you will learn how to convert hexadecimal to char number.
 
More Tutorials...


    Loan Information     Struts     Open Source

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

 
Comments
 
 

 

Understanding Struts Controller

                         

In this section I will describe you the Controller part of the Struts Framework. I will show you how to configure the struts-config.xml file to map the request to some destination servlet or jsp file.

The class org.apache.struts.action.ActionServlet is the heart of the Struts Framework. It is the Controller part of the Struts Framework. ActionServlet is configured as Servlet in the web.xml file as shown in the following code snippets.

 

 

<!-- Standard Action Servlet Configuration (with debugging) -->
<servlet>
     <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
     <init-param>
        <param-name>debug</param-name>
        <param-value>2</param-value>
        </init-param>
        <init-param>
        <param-name>detail</param-name>
        <param-value>2</param-value>
     </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

This servlet is responsible for handing all the request for the Struts Framework, user can map the specific pattern of request to the ActionServlet. <servlet-mapping> tag in the web.xml file specifies the url pattern to be handled by the servlet. By default it is *.do, but it can be changed to anything. Following code form  the web.xml file shows the mapping.

<!-- Standard Action Servlet Mapping -->
<servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
</servlet-mapping>

The above mapping maps all the requests ending with .do to the ActionServlet. ActionServlet uses the configuration defined in struts-config.xml file to decide the destination of the request. Action Mapping Definitions (described below) is used to map any action. For this lesson we will create Welcome.jsp file and map the "Welcome.do" request to this page.

 

 

 

 

Welcome.jsp

<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<html:html locale="true">
<head>
   <title><bean:message key="welcome.title"/></title>
   <html:base/>
</head>
  <body bgcolor="white">
  <h3><bean:message key="welcome.heading"/></h3>
  <p><bean:message key="welcome.message"/></p>
</body>
</html:html>

Forwarding the Welcome.do request to Welcome.jsp

The "Action Mapping Definitions" is the most important part in the struts-config.xml. This section takes a form defined in the "Form Bean Definitions" section and maps it to an action class.

Following code under the <action-mappings> tag is used to forward the request to the Welcome.jsp.

<action  path="/Welcome"
        forward="/pages/Welcome.jsp"
/>
  

To call this Welcome.jsp file we will use the following code.

<html:link page="/Welcome.do">First Request to the controller</html:link>

Once the use clicks on on First Request to the controller link on the index page, request (for Welcome.do) is sent to the Controller and the controller forwards the request to Welcome.jsp. The content of Welcome.jsp is displayed to the user.

 

                         

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

Current Comments

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

Hi,

I tired to do the same things as told. But i am not getting the link wiht the html:link tag.

What can i do?

Posted by amul on Monday, 04.21.08 @ 17:19pm | #57407

hi, I need to learn struts.Please send me
struts materials to my Email.I am trying to
run the struts login example but it showing
Error:Servlet action is not available.What is wrong
in my example.

Posted by vinay kumar on Friday, 04.4.08 @ 12:00pm | #55293

Hello EveryOne,
I wish If any body can hepm me out. I am developing a web site there I need to generate some reports which can be printed if needed. can anybody suggest me how that can be achieved.
I am using Oracle 10g as my backend database.

Posted by subrata on Thursday, 03.27.08 @ 12:12pm | #54471

Dear sir,
I am undergoing a training in struts,please send the struts material to my mail id.
Thanks & Regards

Posted by Shinu on Wednesday, 03.26.08 @ 16:05pm | #54392

RoseIndia is an Excellent site for Learning and .

Posted by venu on Wednesday, 03.26.08 @ 15:48pm | #54391

Hi this is Nagendra,i want a small program to store the name in to database by using struts.

Posted by Nagendrakumar.M on Monday, 03.24.08 @ 17:08pm | #54153

Hi,goodmorning.....
Iam Neelima.

This is very site,just 2days back only i know abt this site...it's very nice
But i want a simple struts example program.
Suppose i want a simple login page,so plz tell me that simple program code...
Thank's 4 giving this oppertinuty......

Posted by Neelima on Tuesday, 02.26.08 @ 12:43pm | #50112

Give a simple and small exmple which help 2 understood problem of struts

Posted by anoop on Thursday, 02.21.08 @ 17:53pm | #49322

I like very much this site "roseindia.net". Because i learned servlets and Jsp form this site. Now iam learning struts..... but i face one problem, every time iam comming to net and lerning. so is there any way to provide pdf file or any other formate

Posted by srinivas on Wednesday, 02.20.08 @ 17:53pm | #49217

Please give information abt what is debug=2 and details=2 and load-on-startup=2..
Your tutorials are too good...

thank you

Posted by Rajesh.K.T on Thursday, 02.14.08 @ 12:50pm | #48241

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.

  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.