Welcome Program using Struts
Previous | Home | Next |
This is basic examples of how you can make a struts application. Here we are going to make only View using JSP Struts Tag Library files. The purpose of this topic is taught you how you can make, run and debug struts application?
You can download "r4r-welcome-program-using-struts.zip" from our website. To do so just copy and past following URL into address bar of your browser http://r4r.co.in/java/struts/basic/tutorial/r4r-welcome-program-using-struts.zip and then change its extension to .war then import it into your workspace by using any IDEs(eclipse or Netbeans).If you are not using IDEs .Then extract it and save it into root folder into tomcat webapp or you can deploy it on tomcat.Then you can see .Here you can see two xml files (web.xml and struts-config.xml ) , one jsp (index.jsp)file,lib folder which includes all required jars. The source code for these files are given below you can explorer these sours code into your work space. To run our struts application start web server and type following on browser http://localhost:8080/r4r-welcome-program-using-struts/index.jsp. Then you will see the output on your browser.Directory Structure of Welcome Example in Struts 1.3 Using MyEclipse IDEindex.jsp<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %><logic:redirect forward="welcomeAction"/>web.xml<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <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>3</param-value> </init-param> <init-param> <param-name>detail</param-name> <param-value>3</param-value> </init-param> <load-on-startup>0</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>struts-config.xml<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://struts.apache.org/dtds/struts-config_1_3.dtd"> <struts-config> <form-beans> <form-bean name="welcomeForm" type="com.r4r.struts.WelcomeForm"/> </form-beans> <global-exceptions /> <global-forwards> <forward name="welcomeAction" path="/welcomeAction.do"/> </global-forwards> <action-mappings> <action path="/welcomeAction" type="com.r4r.struts.WelcomeAction" name="welcomeForm"> <forward name="success" path="/success.jsp"/> </action> </action-mappings> <message-resources parameter="com.r4r.struts.ApplicationResources" /> </struts-config>WelcomeForm.javapackage com.r4r.struts; import org.apache.struts.action.ActionForm; @SuppressWarnings("serial") public class WelcomeForm extends ActionForm { String welcomeMessage; public String getWelcomeMessage() { return welcomeMessage; } public void setWelcomeMessage(String welcomeMessage) { this.welcomeMessage = welcomeMessage; } }WelcomeAction.javapackage com.r4r.struts; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class WelcomeAction extends Action { public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response){ WelcomeForm wel=(WelcomeForm)form; wel.setWelcomeMessage("Kumar Bal Mukund r4r.co.in"); return mapping.findForward("success"); } }success.jsp<%@taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%> <h3>Welcome Example in struts1.3 framework</h3> Welcome,<bean:write name="welcomeForm" property="welcomeMessage"/>Output
Previous | Home | Next |