Hide parameter passed by URL Tag in Struts 2 [dupl

2019-09-19 22:19发布

This question already has an answer here:

In my Struts 2 Application, I am getting a table of values from the database using the iterator tag and using respective getter and setters for the same. For Example I am getting list of Account number, Name and Account Balance.

Now What I wasnt to do is if some one click on the Account number, then the request will be sent to another action class which has required getter and setter and will redirect him to a page where the account details will be shown based on that account number.

Problem is that, as the user clicks the url, value is passed like get parameters so it is very insecure. I want to hide the values.

Currently I am using the following:

<s:url action="custACDetails" var="urlTag" >
    <s:param name="yourAc"><s:property value="acno"/></s:param>
</s:url>
<a href="<s:property value="#urlTag" />" ><s:property value="acno"/></a>

标签: java struts2
1条回答
聊天终结者
2楼-- · 2019-09-19 23:00

You can add a form to trigger a form submit event instead of default link's click event. A form should contain a hidden field to hold a parameter value. Then add javascript code to handle click event.

<s:url action="custACDetails" includeContext="false" var="urlTag"/>
<s:set var="contextPath">${pageContext.request.contextPath}</s:set>
<s:a id="acno" href="%{#contextPath+#urlTag}"><s:property value="acno"/></s:a>
<s:form id="form" action="%{#urlTag}" method="POST">
  <s:hidden name="yourAc" value="%{acno}"/>
</s:form>
<script type="text/javascript">
  $(document).ready(function() {
    $("#acno").click(function(e) {
      e.preventDefault();
      $("#form").submit();
    });
  });
</script>
查看更多
登录 后发表回答