Struts Basics Part 3-Introduction to Java Programming-Lecture Slides, Slides of Java Programming

This is an Introductory course of Java Web Programming focusing on writing maintainable extensible code, methods of debugging, logging and profiling. The Java Technology used is J2EE an Enterprise Application Development tool. This lecture includes: Struts, Model, View, Controller, Tag, Library, Internationalization, Error, Handling, MVC, Flexible, Extensible, Actionform, Class, Action, Logon, Developer

Typology: Slides

2011/2012

Uploaded on 08/09/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
struts-config.xml: <action-mappings>
from struts-submit application
1.<!-- ========== Action Mapping Definitions ============ -->
<action-mappings>
<action path="/submit"
type="submit.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="request"
validate="true">
<forward name="success" path="/submit.jsp"/>
<forward name="failure" path="/submit.jsp"/>
</action>
</action-mappings>
</struts-config>
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Struts Basics Part 3-Introduction to Java Programming-Lecture Slides and more Slides Java Programming in PDF only on Docsity!

struts-config.xml:

from struts-submit application

1.

struts-config.xml:

from struts-example application

   

Global Forwarding

      

Local Forwarding

    docsity.com

ActionForm Bean (Form bean)

 Provided by developer  Define an ActionForm bean (that is, a Java class extending the ActionForm class) for the input form  Define it in struts-config.xml file   name attribute of class  Contains only property getter and property setter methods for each field-no business logic  Provides standard validation mechnism

ActionForm Bean & Controller

 For each ActionForm bean defined in servlet- config.xml file, Controller (ActionServlet) will  Check session scope for an instance of ActionForm bean  If it does not exist, controller creates one  Call corresponding setter method of ActionForm bean for every request parameter whose name corresponds to the name of a property of the bean  Pass the updated ActionForm bean object as a parameter to execute() method of Action class

Example: submit.jsp

1.<%@ page language="java" %><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>  ****  Submit example  ****  Example Submit Page  ****  ****  Last Name: Address: 1.Sex: MaleFemaleMarried:  **Age: **  ** 0 - 19 **  ** 20 - 49 **  ** 50 - **   ****  **** source: Keld Hansen docsity.com

Model: ActionForm

 package submit;
 import javax.servlet.http.HttpServletRequest;
 import org.apache.struts.action.*;
 public final class SubmitForm extends ActionForm {
 /* Last Name */
 private String lastName = "Hansen"; // default value
 public String getLastName() {
 return (this.lastName);
 public void setLastName(String lastName) {
 this.lastName = lastName;
 /* Address */
 private String address = null;
 public String getAddress() {
 return (this.address);
 public void setAddress(String address) {
 this.address = address;
 } source: Keld Hansen

struts-config.xml:

1.

source: Keld Hansen docsity.com

DynaActionForm in Struts 1.

 Instead of creating a new ActionForm subclass and new get/set methods for each of your bean's properties, you can list its properties, type, and defaults in the Struts configuration file  Use DanaActionForm whenever possible  We will learn more about this in Advanced Struts session

source: Chuck Cavaness

Action Class

 Focus on control flow  Process client request by calling other objects (BusinessLogic beans) inside its execute() method  Returns an ActionForward object that identifies a destination resource to which control should be forwarded to  The detination resource could be  JSP  Tile definition  Velocity template  Another Action

Example Action: Logon

 Application needs to  Authenticate a User  Establish a User Session  Error handling  Develop a “LogonAction”

Developer Responsibility: Action Class

 Extend org.jakarta.struts.action.Action  Override  execute() method (in Struts 1.1)  perform() method (in Struts 1.0)