【问题标题】:How to write expression in <s:textfield value" ">如何在 <s:textfield value" "> 中编写表达式
【发布时间】:2014-12-24 08:30:38
【问题描述】:

您好朋友,我正在尝试将解密值表达式写入 s:textfield value"" 类似的内容,但它给了我一个错误,即根据标记文件中的 TLD 或属性指令,属性值不接受任何表达式,那么在 .请帮帮我。在 INPUT 中输入它运行良好,但我想通过 struts 标记做同样的事情。

这是我的代码

    <s:iterator value="userList">
        <s:set var="custFirstName" value="custFirstname"/>
        <s:set var="custLastName" value="custLastname"/>
        <s:set var="custEmail" value="custEmail"/>
        <s:set var="custPhone" value="custPhone"/>
        <s:set name="custVerified" value="custIsVerified"/>
        <%
        String custFirstName = pageContext.getAttribute("custFirstName").toString();
        String custLastName = pageContext.getAttribute("custLastName").toString();
        String custEmail = pageContext.getAttribute("custEmail").toString();
        String custPhone = pageContext.getAttribute("custPhone").toString();

        Encryption encryption=new Encryption();
        custFirstName = Encryption.decString(custFirstName);
        custLastName = Encryption.decString(custLastName);
        custEmail = Encryption.decString(custEmail);
        custPhone = Encryption.decString(custPhone);
    %>




            <td> <s:textfield value="<%=custFirstName%>" label="First Name"/></td>
            <%-- <input type="text" value="<%=custFirstName%>" > --%>
            <td> <s:textfield name="custLastName" label="Last Name"/></td>
            <td> <s:textfield name="custEmail" label="Email"/></td>
            <td> <s:textfield name="custPhone" label="phone"/></td>
            <td> <s:textfield name="custCountry" label="Country"/></td>
            <td> <s:textfield name="custState" label="State"/></td>
            <td> <s:textfield name="custCity" label="City"/></td>
            <s:submit value="Update"></s:submit>

    </s:iterator>   

</s:form>



<input type="text "value="<%=custFirstName%>">

我想将上面的输入值表达式写入 s:textfield value="" 我该怎么做。

【问题讨论】:

  • 这是一个脚本值...??
  • 在 JSP 中不鼓励使用 scriptlet,并且不允许在 struts 标记中使用。您应该使用更好的方法。为什么需要在 JSP 中编写业务逻辑?
  • 我知道这不是一个好方法,但我想解密我正在使用的值

标签: jsp struts2 ognl valuestack struts-tags


【解决方案1】:

你可以使用类似的东西:

<td> <s:textfield value="%{#custFirstName}" label="First Name"/></td>

【讨论】:

  • 我也用过这个,但它显示的是加密值而不是解密值
  • 解密值后带上您的 c:set 标签,以便它们反映解密的值而不是加密的值。
  • 你解密后用&lt;s:set var="custFirstName"&gt;&lt;%=custFirstName%&gt;&lt;/s:set&gt;了吗?如果不这样做,这是分配值的正确方法。
  • 是的,这是一个有效的问题,而且它的格式和解释都很好。所以+1。
【解决方案2】:

你需要设置value属性,没错,但应该是OGNL表达式。

Encryption encryption=new Encryption();
custFirstName = Encryption.decString(custFirstName);
custLastName = Encryption.decString(custLastName);
custEmail = Encryption.decString(custEmail);
custPhone = Encryption.decString(custPhone);
ValueStack vs = ActionContext.getContext().getValueStack();
vs.set("custFirstName", custFirstName);
vs.set("custLastName", custLastName);
vs.set("custEmail", custEmail);
vs.set("custPhone", custPhone);

然后你就可以使用OGNL了

<s:textfield name="custFirstName" value="%{#custFirstName}" label="First Name"/>

...

你也可以看看这个Struts 2 Value Stack/OGNL

【讨论】:

  • 不,它不工作它告诉我加密值不是解密值
  • 我不知道这个Encryption 类在做什么,但解密或未解密的值在 JSP 的文本字段中显示
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
  • 2012-11-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多