How to assign value to a jsp variable

前端 未结 4 690
一个人的身影
一个人的身影 2020-12-19 22:34

Can anybody tell how to assign a value coming from \"\" into jsp variable ?

相关标签:
4条回答
  • 2020-12-19 23:08

    you can use the following to get the value in to variable,

    For example there is a string avalue,

    String avalue="";

    Now you can assign a property value to it by using,

    <s:property value="a"/>
    avalue=request.getAttribute("a");
    

    above will gives the property value to a string variable. otherwise u can set the value and then assign it through getAttribute.

    0 讨论(0)
  • 2020-12-19 23:13

    The struts property tag generates output not input. If you want to do something else with the value that s:property would output, the equivalent code would be getA(), which is what s:property will use to get the value that it will print.

    https://cwiki.apache.org/WW/property.html

    0 讨论(0)
  • 2020-12-19 23:18

    You can use the s:set tag for this.

    For example this will call getA() from your action and put the value into "avalue", don't use name instead of var

    <s:set var="avalue" value="a" />
    

    And then you can reference it like so on the JSP:

    <b>Print value defined in set tag :</b> <s:property value="#avalue" /> <br/>
    

    Which will print out the value.

    0 讨论(0)
  • 2020-12-19 23:23

    As Tim mentioned, <s:property value="a"/> is equivalent to calling the action's getA() method. You can get this using the JSP EL as ${action.a}.

    If you need to evaluate an OGNL expression and store that in an EL variable, you would probably need a custom tag.

    0 讨论(0)
提交回复
热议问题