Struts2,无法使用< s:include>访问参数标签.想要在< s:if>中使用它标签 [英] Struts2, Cannot access param using <s:include> tag. Want to use it in <s:if> tag

查看:92
本文介绍了Struts2,无法使用< s:include>访问参数标签.想要在< s:if>中使用它标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,我需要将我的资产净值栏放在每页的顶部.因此,我决定在每个页面中都包含一个新的JSP,该页面中的参数指示用户所使用的活动选项卡是什么.

I have a situation that I need to put my NAV bar at the top of each page. So I decided to Include a new JSP in each page having a parameter indicating the what is the active tab the user is on.

我的实现如下.

dashboard.jsp

...
<s:include value="../tab-set.jsp">
    <s:param name="tab_name" value="dashboard" />
</s:include>
...

tab-set.jsp

<nav>
    <ul>
        <li <s:if test="param.tab_name == 'dashboard'">class="active"</s:if> >
            <a href="dashboard">Dashboard</a>
        </li>
        <li <s:if test="param.tab_name == 'tab_2'">class="active"</s:if> >
            <a href="suggestion">TAB 2</a>
        </li>
    </ul>
</nav>

结果是IF大小写不在两个选项卡上都执行.

The result is that IF case do not execute on both tabs.

我也尝试了不同的方法,但是它不起作用

I have also tried it with different approaches but its not working like

<s:if test="#param.tab_name == 'dashboard'">

OR

<s:if test="#attr.tab_name == 'dashboard'"> (在网上找到了某个地方)

或者我也尝试使用${param.tab_name}在页面上打印tab_name值,但是什么也没发生.

OR I also tried to print the value of tab_name value on page using ${param.tab_name} but nothing happened.

但是它们都不起作用.

请帮助我或指导我该怎么做.

Please help me or guide me what I can do instead.

谢谢.

推荐答案

无法以这种方式访问​​参数,因为未在渲染页面中创建valuestack.尝试像请求参数${param.tab_name}一样访问它们.

The parameters cannot be accessed that way because valuestack is not created within rendered page. Try to access them like request parameters ${param.tab_name}.

更新

<s:param>标记的值应为'dashboard',因为它是一个字符串.

The value of <s:param> tag should be 'dashboard' because it is a string.

<s:include value="../tab-set.jsp">
    <s:param name="tab_name" value="'dashboard'" />
</s:include>

在包含的页面中,使用${param.tab_name}表示法获取tab_name,然后使用<s:set>标记将其设置为其他变量.

In your included page get tab_name using ${param.tab_name} notation and set it to some other variable using <s:set> tag.

<s:set name="tabName">
   ${param.tab_name}
</s:set>
<s:if test="#tabName == 'dashboard'">
</s:if>

这样,就不需要使用片段了.

This way there is no need to use scriplets.

这篇关于Struts2,无法使用&lt; s:include&gt;访问参数标签.想要在&lt; s:if&gt;中使用它标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆