7:19 am - Saturday December 20, 2014

struts 1x tiles with example program In Eclipse


Step by Step tutorial on running  your  Struts Tiles  application in Tomcat5.5 with Eclipse IDE

Step – 1 Creating Dynamic web Project

Step – 2 Struts Tiles  STRUTS folder structure

Step – 3 Creating your  Struts Tiles  program(Controller)

Step – 4 Creating web.xml for Struts Tiles  application

Step – 5 Creating Struts-config.xml

Step – 6 Struts Tiles  Struts view page

Step – 7 How to Add server in   Struts Tiles   application

Step – 8 OutPut  for  Running  Struts Tiles  application

 

Start Eclipse and goto File -> New -> Project -> Dynamic Web Project

Following is the list of required JAR files to be added in Java Class Path of your project. Download displaytag JAR files from

JAR FILES + TLD FILES

Step – 2 Struts Tiles  STRUTS folder structure

Lib Folder

 

Download The Following TLD files  and paste into WEB-INF

Step – 3 Creating your  Struts Tiles  program(Controller & Properties)

LinkAction.java

package Com.Candidjava;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;

public class LinkAction extends DispatchAction {

	/**
	 * This is the Struts action method called on
	 * http://.../actionPath?method=myAction1, where "method" is the value
	 * specified in  element : (  )
	 */
	public ActionForward java(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("java");
	}

	/**
	 * This is the Struts action method called on
	 * http://.../actionPath?method=myAction2, where "method" is the value
	 * specified in  element : (  )
	 */
	public ActionForward j2ee(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("j2ee");

	}

	public ActionForward struts(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("struts");

	}

	public ActionForward hibernate(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		return mapping.findForward("hibernate");

	}

}

ApplicationResource.properties

# -- standard errors --
errors.header=</pre>
<ul>
<ul>errors.prefix=
	<li>errors.suffix=</li>
</ul>
</ul>
<ul>errors.footer=</ul>
<pre>
# -- validator --
errors.invalid={0} is invalid.
errors.maxlength={0} can not be greater than {1} characters.
errors.minlength={0} can not be less than {1} characters.
errors.range={0} is not in the range {1} through {2}.
errors.required={0} is required.
errors.byte={0} must be an byte.
errors.date={0} is not a date.
errors.double={0} must be an double.
errors.float={0} must be an float.
errors.integer={0} must be an integer.
errors.long={0} must be an long.
errors.short={0} must be an short.
errors.creditcard={0} is not a valid credit card number.
errors.email={0} is an invalid e-mail address.
# -- other --
errors.cancel=Operation cancelled.
errors.detail={0}
errors.general=The process did not complete. Details should follow.
errors.token=Request could not be completed. Operation is not in sequence.
# -- welcome --
welcome.title=Struts Application
welcome.heading=Struts Applications in Netbeans!
welcome.message=It's easy to create Struts applications with NetBeans.

Step – 4 Creating web.xml for Struts Tiles  application




	Struts Blank Application

	
		action
		org.apache.struts.action.ActionServlet
		
			config
			/WEB-INF/struts-config.xml
		
		
			debug
			2
		
		
			detail
			2
		
		2
	

	
		action
		*.do
	

	
		index.jsp
	
	
		/tags/struts-html
		/WEB-INF/struts-html.tld
	
	
		/tags/struts-bean
		/WEB-INF/struts-bean.tld
	
	
		/tags/struts-tiles
		/WEB-INF/struts-tiles.tld
	



Step – 5 Creating Struts-config.xml

<!--?xml version="1.0" encoding="UTF-8" ?-->





	
		
			
			
			
			
		

	

	

	

	<!-- 		============= Tiles plugin ============= 	-->

	
		
		
	


tiles-defs.xml

<!--?xml version="1.0" encoding="UTF-8" ?-->

 

	<!-- 		This is a blank Tiles definition file with a commented example. 	-->



	<!--
		sample tiles definitions <definition name=".mainLayout" 		path="/common/layouts/classicLayout.jsp"> <put name="title" 		value="Sample Page Title" /> <put name="header" 		value="/common/header.jsp" /> <put name="menu" value=".mainMenu" />
		<put name="footer" value="/common/footer.jsp" /> <put name="body" 		value=".portal.body" /> </definition> <definition name=".mainMenu" 		path="/common/layouts/vboxLayout.jsp" > <putList name="list" > <add 		value=".menu.links" /> <add value=".menu.taglib.references" /> <add 		value=".menu.printer.friendly" /> <add value=".menu.old.documents" />
		</putList> </definition> <definition name="aPage" 		extends=".mainLayout"> <put name="title" value="Another Title" /> <put 		name="body" value=".aPage.body" /> </definition> end samples
	-->

	
	

	
		

	
	
		
		

	
	
		

	
	
		
		

	
	
		
		

	

Step – 6 Struts Tiles  Struts view page 

baseLayout.jsp











</pre>
<table border="1" cellspacing="2" cellpadding="2" align="center">
<tbody>
<tr>
<td colspan="2" height="20%"></td>
</tr>
<tr>
<td colspan="2" height="10%"></td>
</tr>
<tr>
<td width="50%" height="250"></td>
</tr>
<tr>
<td colspan="2" height="20%"></td>
</tr>
</tbody>
</table>
<pre>


body.jsp






    
        
        JSP Page
    


 sample body content.



footer.jsp






    
    

</pre>
<div align="center">Candid industrial training</div>
<pre>


header.jsp




    
    

</pre>
<div style="font-weight: bold;" align="center">Java Cources</div>
<pre>


hibernate.jsp








        JSP Page



More details about hibernate here...



index.jsp







Struts Tiles











j2ee.jsp








        JSP Page



More details about j2ee here...



java.jsp








        JSP Page



More details about java here...



menu.jsp








JSP Page


<a href="Link.do?method=java">Java</a>
<a href="Link.do?method=j2ee">J2ee</a>
<a href="Link.do?method=struts">Struts</a>
<a href="Link.do?method=hibernate">Hibernate</a>


struts.jsp








        JSP Page



More details about struts here...



Step – 7 How to Add server in   Struts Tiles   application

Window –>show view—->servers—>add new–>          

Select ther version which you installed in your System

How to run the Project:

Right click on project name———–>click Run As —> Run On Server

Step – 8 OutPut  for  Running  Struts Tiles  application  BACK

Filed in: Z-AStruts Codes

No comments yet.

Leave a Reply