Friday, 17 October 2014

how to pass a value from one jsp in tiles to another jsp in different tiles definition in Struts 2



I want to send data from a link in a jsp page to another jsp page.As the data is in a jsp page in a link and there are 3-4 of them as they show data that is fetch from database.



<a href="Product" ><%= str1[0] %></a>
<a href="Product" ><%= str1[1] %></a>
<a href="Product" ><%= str1[2] %></a> .


The str1[] is an array of String that contain the data item fetch from the database. Now , as soon as i click this link, it will go to struts.xml struts.xml



<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://ift.tt/1tkDVrF">
<struts>

<package name="default" extends="tiles-default">
<action name="home" class="com.deviceous.Success1">
<result name="success" type="tiles">Home1</result>
</action>

<action name="Product" class="com.deviceous.Success1">
<result name="success" type="tiles">Product1</result>
</action>
</package>
</struts>


Then it will find an action mapped with the same name and then proceed further to a class



import com.opensymphony.xwork2.ActionSupport;
public class Success1 extends ActionSupport
{
public String execute()
{
return "success";
}


}`


function will be will return success and then the struts will pass control to tiles.xml tiles.xml



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

<!DOCTYPE tiles-definitions PUBLIC `"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://ift.tt/19E1atl">
<tiles-definitions>

<definition name="Home1" template="HomePageJSP/HomePage.jsp">
<put-attribute name="header" value="/HomePageJSP/Header.jsp"/>
<put-attribute name="leftMenu" value="/HomePageJSP/LeftMenu.jsp"/>
<put-attribute name="body" value="/HomePageJSP/Body.jsp"/>
<put-attribute name="footer" value="/HomePageJSP/Footer.jsp"/>
</definition>

<definition name="Product1" template="ProductJSP/Structure.jsp">
<put-attribute name="header" value="/HomePageJSP/Header.jsp"/>
<put-attribute name="leftMenu" value="/HomePageJSP/LeftMenu.jsp"/>
<put-attribute name="body" value="/ProductJSP/Body.jsp"/>
<put-attribute name="footer" value="/HomePageJSP/Footer.jsp"/>
</definition>


</tiles-definitions>


which will send to a layout which contains body.jsp .


Now i want to access the data about which link was clicked in the starting in body.jsp.


Any help will mean a lot . Thank you.


No comments:

Post a Comment