如何动态制作标题?
我正在struts2和tiles(2)框架中开发BBS。
我想在 ActionSupport 类中推送一个值,并在tiles的layout.jsp中弹出该值。但我一直无法获得价值。
我将一步步解释我的作品。
1) 用户点击列表页面的链接查看文章。 中的定义进行调用
BoardView 类将按照 struts.xml --list.jsp--${ subject }
--struts.xml--<操作名称=“View_board”类=“board.BoardView”>
<结果类型=“图块”>board.view
2)Action 类会将 title 放入值堆栈中...对吗?
--BoardView 类--
public class BoardView extends ActionSupport
private String title;
public void Execute() throws Exception {
...
setTitle(board.getSubject());
return SUCCESS;
}
...
(setter and getter of title)
3) 当 ActionClass 返回 SUCCESS 时,它将转到名为 board.view 的图块定义
--struts.xml--<操作名称=“View_board”类=“board.BoardView”>
<结果类型=“图块”>board.view
4)这是tiles-def.xml 和问题。我认为“标题”的值无法从值堆栈中弹出。
==tiles-def.xml==
(我无法缩进标签...抱歉)
这是layout.jsp ==layout.jsp==
<代码>... <标题>
我尝试将 value 属性替换为 %{title}、$title 和 ${title}。但一切都没有结果。 Web 浏览器仅显示字符串本身($title)。
我不知道该怎么办...请帮助我。
尽管我的解释很糟糕,但我希望你们都能理解我的作品。
I'm developing BBS in struts2 and tiles(2) framework.
I want to push a value in ActionSupport class and pop the value in layout.jsp of tiles. but i just keep failing to access to the value.
I will explain my works step by step.
1) Users click a link to view an article at list page. And BoardView class will be called as defined in struts.xml
--list.jsp--<a href="view_board?num=${num}"> ${ subject } </a>
--struts.xml--<action name="View_board" class="board.BoardView">
<result type="tiles">board.view</result>
</action>
2)Action class will put title into the value stack... right?
--BoardView class--
public class BoardView extends ActionSupport
private String title;
public void Execute() throws Exception {
...
setTitle(board.getSubject());
return SUCCESS;
}
...
(setter and getter of title)
3) As ActionClass returns SUCCESS, it will go to tiles definition named board.view
--struts.xml--<action name="View_board" class="board.BoardView">
<result type="tiles">board.view</result>
</action>
4)Here's the tiles-def.xml and the problem. I think the value of 'title' can't be popped from value stack.
==tiles-def.xml==<definition name="board.view" extends="layout">
<put-attribute name="title" value="%title" />
<put-attribute name="body" value="/board/view.jsp" />
</definition>
(I can't indent with tags... sorry)
Here's the layout.jsp
==layout.jsp==...
<title><tiles:getAsString name="title" /></title>
...
I tried to replace the value attribute to %{title}, $title and ${title}. But nothings worked out. Web Browser just shows the string itself($title).
I don't know what to do... please help me.
I hope you all understand my works despite my bad explanation.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为我当前项目的解决方案。
As my solution on current Project.
<c:out value="${pageTitle}" default="My Title"></c:out>