Understanding Struts Action Class: Signature, Parameters, and Configuration, Lecture notes of Java Programming

The role of the action class in the struts framework, providing its signature, parameters, and an example of its configuration in the struts-config.xml file. It also demonstrates how to test an action class by adding a link in the index.jsp file.

Typology: Lecture notes

2011/2012

Uploaded on 08/09/2012

dhanyaa
dhanyaa 🇮🇳

4.7

(3)

60 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Understanding Action Class
Here is the signature of the Action Class.
public ActionForward execute(ActionMapping mapping,
ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
throws java.lang.Exception
Action Class process the specified HTTP request, and create the corresponding HTTP
response (or forward to another web component that will create it), with provision for
handling exceptions thrown by the business logic. Return an ActionForward instance
describing where and how control should be forwarded, or null if the response has
already been completed.
Parameters:
mapping - The ActionMapping used to select this instance
form - The optional ActionForm bean for this request (if any)
request - The HTTP request we are processing
response - The HTTP response we are creating
Throws:
Action class throws java.lang.Exception - if the application business logic throws
an exception
Adding the Action Mapping in the struts-config.xml
To test the application we will add a link in the index.jsp
<html:link page="/TestAction.do">Test the Action</html:link>
Following code under the <action-mappings> tag is used to for mapping the
TestAction class.
<action path="/TestAction" type="sturtTest.TestAction">
<forward name="testAction" path="/TestAction.jsp"/>
</action>
To test the new application click on Test the Ac t i o n link on the index page. The
content of TestAction.jsp should be displayed on the user browser.
docsity.com
pf2

Partial preview of the text

Download Understanding Struts Action Class: Signature, Parameters, and Configuration and more Lecture notes Java Programming in PDF only on Docsity!

Understanding Action Class Here is the signature of the Action Class.

public ActionForward execute (ActionMapping mapping, ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception

Action Class process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. Return an ActionForward instance describing where and how control should be forwarded, or null if the response has already been completed.

Parameters:

mapping - The ActionMapping used to select this instance form - The optional ActionForm bean for this request (if any) request - The HTTP request we are processing response - The HTTP response we are creating

Throws: Action class throws java.lang.Exception - if the application business logic throws an exception

Adding the Action Mapping in the struts-config.xml To test the application we will add a link in the index.jsp <html:link page="/TestAction.do">Test the Action</html:link>

Following code under the <action-mappings> tag is used to for mapping the TestAction class.

To test the new application click on Test the Action link on the index page. The content of TestAction.jsp should be displayed on the user browser.

docsity.com

In this l struts-co TestActi

lesson you l onfig.xml. on.jsp.

learned how Our Action

w to create Class retur

e Action Cla rns the Act

ass and add tionForward

d the mapp d mapping

pings in the g of the

e

docsity.com