admin管理员组

文章数量:1434909

I need to change (parse) one of the object property. Is it any way I can save the parse value in the js variable and then pass it back. This is what I tried but it does not work:

    <c:forEach var="user" items="${requestScope.users}">
       var parsedName= parseUserName("${user.name}");
       <c:set target = "${user}" property = "parsedName" value ="${parsedName}"/>  
    </c:forEach>

I need to change (parse) one of the object property. Is it any way I can save the parse value in the js variable and then pass it back. This is what I tried but it does not work:

    <c:forEach var="user" items="${requestScope.users}">
       var parsedName= parseUserName("${user.name}");
       <c:set target = "${user}" property = "parsedName" value ="${parsedName}"/>  
    </c:forEach>
Share Improve this question asked Nov 16, 2016 at 15:21 user5783530user5783530 2511 gold badge4 silver badges16 bronze badges 3
  • This looks like XY Problem. Could you include information about a broader picture of the problem? – acm Commented Nov 16, 2016 at 15:30
  • I need to show some user information in my html, but one of the field(name) has to be parsed first – user5783530 Commented Nov 16, 2016 at 15:31
  • Add Hole case Scenario rather then just small glimpse of it. Include what you want to parse and how you want to parse and obviously that includes why... – Shalin Patel Commented Nov 17, 2016 at 12:22
Add a ment  | 

3 Answers 3

Reset to default 2

Your idea is:

<c:forEach var="user" items="${requestScope.users}">
    <script type="javascript">
        var parsedName= parseUserName("${user.name}");
    </script>
    <c:set target = "${user}" property = "parsedName" value ="${parsedName}"/>
</c:forEach>

unfortunately it is not possible.

The jstl code happen on the server side and javascript on the client side.

No it is not possible to do what you are trying to do. The only possible solution is to send the variable to the server using a partial refresh and set the required property once the page has been refreshed

If possible try to implement the parseUserName() logic in JSP itself using JSTL.

If you need help with that post the JS method logic here.

本文标签: javaPass javascript variable to jstl tagsStack Overflow