Magazine
 
Struts 1.1

own web application.

struts-documentation.war includes important documents and API for the struts application development.

struts-example.war is simple MailReader Demonstration Application.

Developing First Struts Application

Rename struts-blank.war to StrutsApplication.war from jakarta-tomcat- 5.0.4\webapps and copy it to the “jakartatomcat- 5.0.4\webapps” directory. Tomcat
automatically extracts the file and loads the application.

Copy the source files (LookupDispatch_Action.java and MappingDispatch_Action.java) into the source directory (src directory), jsp files MappingDispatchAction.jsp and
MappingDispatchActionSave.jsp into the pages directory, index.jsp file in the StrutsApplication directory parallel to the pages and WEB-INF directory, struts-config.xml, web.xml, strutsbean. tld, and struts-html.tld parallel to the lib and the classes directory in the WEB-INF directory, and finally copy the servlet-api.jar and struts.jar files into the lib directory and then compile the whole application, start the tomcat server, open the browser and enter the url http:/ /localhost:8080/StrutsApplication/ and then
press enter, if everything is ok then the welcome page (that is index.jsp in case of our application) will be displayed. Here are the different files used in our application.

LookupDispatch_Action.java

ackage roseindia.net;
import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import
javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;
import
org.apache.struts.actions.LookupDispatchAction;
import org.apache.struts.action.ActionForm;

 

import
org.apache.struts.action.ActionForward;
import
org.apache.struts.action.ActionMapping;
public class LookupDispatch_Action extends
LookupDispatchAction {
protected Map getKeyMethodMap(){
Map map = new HashMap();
map.put(“roseindia.net.add”,”add”);
map.put(“roseindia.net.edit”,”edit”);
map.put(“roseindia.net.search”,”search”);
map.put(“roseindia.net.save”,”save”);
return map;
}
public ActionForward add(ActionMapping
mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception{
System.out.println(“You are in add
function.”);
return
mapping.findForward(“add”);
}
public ActionForward edit(ActionMapping
mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception{
System.out.println(“You are in edit
function.”);
return mapping.findForward(“edit”);
}
public ActionForward search(ActionMapping
mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception{
System.out.println(“You are in search
function”);
return
mapping.findForward(“search”);
}
public ActionForward save(ActionMapping
mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception{
System.out.println(“You are in save
function”);
return

Mar 2008 | Java Jazz Up | 25
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59,

Download PDF