tiles的使用问题

wangxiaomax 2004-03-15 03:54:46
ListLayout.jsp布局文件
<html>
<head>
<title>
<tiles:getAsString name="title" ignore="true"/>
</title>
</head>
<BODY>
<tiles:insert attribute="head" ignore="true"/>
<%
//如何显示title
//out.println(title);
%>
<tiles:insert attribute="footer" ignore="true"/>
</body>
</html>

tiles_defs.xml定义文件
<definition name="ListLayoutDef" path="/tiles/ListLayout.jsp">
<put name="title" type="string" value="List Page" />
<put name="head" value="/head.jsp" />
<put name="footer" value="/footer.jsp" />
</definition>

TestList.jsp使用布局文件
<tiles:insert definition="ListLayoutDef" flush="true">
<tiles:put name="title" type="string">
hello world
</tiles:put>
</tiles:insert>

由于我的查询页面,里面有很多重复的JAVA代码,所以我要把此重复代码放在布局文件里。这样就出现了一个问题,如何在布局文件ListLayout.jsp里的JAVA代码里取TestList.jsp文件里PUT的值。也就是如何显示title?
...全文
72 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wangxiaomax 2004-03-16
  • 打赏
  • 举报
回复
多谢sagittarius1979(射手爱狮子) ,现在搞定了。
sagittarius1979 2004-03-15
  • 打赏
  • 举报
回复
这个倒是个问题。楼主在jsp中这样设值没有是过,不过提供一个思路:

import org.apache.struts.action.*;
import org.apache.struts.tiles.*;
import org.apache.struts.tiles.actions.TilesAction;

import java.io.IOException;
import javax.servlet.http.*;
import javax.servlet.ServletException;

public class tilesAction extends TilesAction {

/**
* perform
* @param context ComponentContext
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws IOException
* @throws ServletException
* @return ActionForward
*/
public ActionForward perform(ComponentContext context,
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
System.out.println("========= in bAction.perform() ==========");
String sTitle = (String)context.getAttribute("title");
context.putAttribute("title","My title");
return null;
}
}

struts-config.xml中:
<action path="/MyTilesAction" type="jp.co.sis.tilesAction" />


再传到jsp。
jsp中:
<tiles:insert page="/layout/layout.jsp" controllerUrl="/MyTilesAction.do">
<tiles:put name="title" value="C's titles"/>
<tiles:put name="header" value="/common/header.jsp"/>
<tiles:put name="body" value="/common/body.jsp"/>
<tiles:put name="footer" value="/common/footer.jsp"/>
</tiles:insert>

这样显示的jsp中title的值为:My title
wangxiaomax 2004-03-15
  • 打赏
  • 举报
回复
有没有人知道啊?
花了周末的时间,看完了IBM的“掌握Tiles框架”,这个问题没法解决,极度郁闷。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧