【问题标题】:Comparing Struts 2 Iterator Objects with Spring Security Context将 Struts 2 迭代器对象与 Spring Security Context 进行比较
【发布时间】:2011-01-17 01:57:18
【问题描述】:

假设我在对象列表上使用 Struts 2 迭代标记。每个对象都有一个名为 creatorUserId 的属性。

我想将 creatorUserId 与当前登录用户的 Id 号进行比较。

如何在 JSP 页面中使用 Spring Security 和 Struts 2 执行此操作?

<security:authentication property="principal.userID" />显示当前用户的ID号

<s:property value="creatorUserId" /> 显示当前迭代器项的 creatorUserId。

我想做:

<s:if test="%{creatorUserId == <security:authentication property='principal.userID' />}">

但这不是合法的表达方式。

谁能帮忙分析一下语法?

【问题讨论】:

    标签: java struts2 spring-security


    【解决方案1】:

    我不熟悉 Struts,但 &lt;security:authentication&gt; 有一个 var 属性可以将其结果导出为命名上下文属性:

    <security:authentication var = "userId" property = "principal.userID" /> 
    <c:if test = "%{creatorUserId == userId}"> 
    

    【讨论】:

      猜你喜欢
      • 2020-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-21
      • 2022-09-30
      • 1970-01-01
      • 2010-11-14
      相关资源
      最近更新 更多