Struts Basics Part 4-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, Action, Class, HTTP, ForwardAction, DispatchAction

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
execute(..) method of Action class
(Struts 1.1 only)
Invoked by controller
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception;
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

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

execute(..) method of Action class

(Struts 1.1 only)

 Invoked by controller

public ActionForward execute(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws Exception;

perform(..) method of Action class

(Struts 1.0 only)

 Deprecated

public ActionForward perform(

ActionMapping mapping,

ActionForm form,

HttpServletRequest request,

HttpServletResponse response)

throws IOException, ServletException;

Example: Action Class

1.package submit; import javax.servlet.http.; import org.apache.struts.action.; public final class SubmitAction extends Action {  public ActionForward execute(ActionMapping mapping,  ActionForm form,  HttpServletRequest request,  HttpServletResponse response) {  SubmitForm f = (SubmitForm) form; // get the form bean  // and take the last name value  String lastName = f.getLastName();  // Translate the name to upper case

  1. //and save it in the request object  request.setAttribute("lastName", lastName.toUpperCase());   // Forward control to the specified success target  return (mapping.findForward("success"));  } } docsity.com

Design Guidelines of Action Class

 The controller Servlet creates only one instance of

your Action class, and uses it for all requests

 Action class has to be in multi-threaded safe  Use local variables (as opposed to instanace variables)

 Make Action class a thin layer

 Use Model components for complex business logic handling

struts-config.xml: ActionMapping

Pre-built Action Classes

 ForwardAction

 DispatchAction

 We will learn more about these in Advanced Struts

session

Model Components

 Model divided into concepts

 Internal state of the system  Business logic that can change that state

 Internal state of system represented by

 JavaBeans  Enterprise JavaBeans  POJO's  JDO  JDBC  Whatever

source: Chuck Cavaness

docsity.com

 `

source: Chuck Cavaness

View Components

 JSP files which you write for your specific application

 Set of JSP custom tag libraries

 Resource files for internationalization

 Allows for fast creation of forms for an application

 Works in concert with the controller Servlet

Forms and FormBean Interactions

 If the user makes an error, the application should

allow them to fix just what needs to be changed

 With just JSP, you have to do

 With Struts, you can do

;

Example: submit.jsp

**1.<%@ page language="java" %> 2.<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 3.<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 4.<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

2.Submit example

1.Example Submit Page

2.Last Name: 3.Address: 4.Sex: Male**

5. Female

**6.Married: 7.Age: **

  • ** 0 - 19
  1. 20 - 49
  2. 50 -
  3. **

1. docsity.com

web.xml

Web App Deployment Descriptor

(web.xml)

 Struts application is a Web application

 Follows the same rule  Has to have web.xml deployment descriptor

 web.xml includes:

 Configure ActionServlet instance and mapping  Resource file as  servlet-config.xml file as  Define the Struts tag libraries

 web.xml is stored in WEB-INF/web.xml