如何动态制作标题?

发布于 2024-08-27 18:09:23 字数 1535 浏览 2 评论 0原文

我正在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

椒妓 2024-09-03 18:09:23

作为我当前项目的解决方案。

  1. 在模板 jsp 中: put
  2. 因此,在每个 actions 类中,您应该创建变量 pageTitle 为 DYNAMIC Title。

As my solution on current Project.

  1. In template jsp: put <c:out value="${pageTitle}" default="My Title"></c:out>
  2. So, in every actions class, you should create the variable pageTitle to DYNAMIC Title.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文