Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

          Recently i while doing a R&D sort of thing on my ide’s (eclipse and netbeans) i encountered on a struts 2 application.I read its documentation on the page and decided to give it a try as i went through the features.Getting started with struts 2 was a piece of cake , more ever with the site-mesh integration it just blew me off.It worked fine.However off late i encountered a requirement stating usage of tiles with struts 2 .Initially i thought of it as easy but as i ususally feel of easy things , it turned out to be real pain.Eventually a couple of hours of fight saw me through the struts 2 defences and led to a good integration of tiles2 with struts .This is a walk through is to achieve the same.The versions for struts 2 and tiles 2 used are 2.0.6 and any further versions haven’t been tested by me.

          Assumptions:

          • JDK 1.5 installed
          • Tomcat 6.0 installed
          • You can create a struts 2 web application in eclipse or any other ide.

          The process involves the following steps:

          1. Download the binaries
          2. Changing the configuration files for application.

          1.Download the binaries

          I have used struts 2.0.6 libraries , which can be downloaded from Here .

          Tiles 2.0.6 binaries can be downloaded from Here

          Extract the jar’s from both the zip files and put them in your lib directory of your web project.

          2. Changing the configuration files for application.

          This involves changing web.xml ,struts.xml and tiles .xml

          web.xml

          Add following section to web.xml

          <listener>
          <listener-class>
          org.apache.struts2.tiles.StrutsTilesListener
          </listener-class>
          </listener>

          <context-param>

          <param-name>tilesDefinitions</param-name>
          <param-value>/WEB-INF/tiles.xml</param-value>
          </context-param>

          struts.xml
          add following section to struts.xml

          <package name=”org.action” extends=”tiles-default” >
          <action name=”myaction” class=”org.action.YourAction”>
          <result name=”INPUT” type=”tiles”>tiles:test</result>
          </action>
          </package>

          here “org.action” is the package name in which the action class resides.

          tiles.xml

          add the following snippet to tiles.xml file within “tiles-definitions”

          <definition name=”tiles:layout” template=”/WEB-INF/pages/layout.jsp”>
          <put name=”body” value=”"/>
          </definition>
          <definition name=”tiles:test” extends=”tiles:layout”>
          <put name=”body” value=”/WEB-INF/pages/test.jsp”/>
          </definition>

          Rest of the struts 2 application remains unaltered. Note that tiles.xml should be in WEB-INF folder as mentioned in the web.xml.The jsp’s and action should be present at correct locations and its all done .

          posted on 2009-03-22 22:25 seal 閱讀(317) 評論(0)  編輯  收藏 所屬分類: Struts
          主站蜘蛛池模板: 辉南县| 日照市| 陵水| 满洲里市| 安庆市| 濉溪县| 新建县| 榕江县| 玛纳斯县| 南平市| 郯城县| 长乐市| 洪洞县| 东辽县| 乌兰浩特市| 镇赉县| 永靖县| 祁连县| 铅山县| 阿拉善左旗| 吴桥县| 芮城县| 大宁县| 溧水县| 马关县| 浦北县| 衢州市| 湖口县| 东乡族自治县| 新疆| 富顺县| 石狮市| 阿克苏市| 兴安县| 阿克| 唐山市| 禹州市| 汨罗市| 罗甸县| 钟山县| 隆安县|