Change display URL in struts 2 to hide request parameters

天涯浪子 提交于 2019-12-11 12:53:44

问题


I know very well that using GET method and passing request parameters in URL is a bad practice and security vulnerability . But we are in a situation where project development is almost completed and we can not afford to change all the GET to POST and re-test the whole thing all over again.

Is there a way to change the displayed URL ?

Or URL encoding will do the job ? Please suggest what could be the best approach in this situation.


回答1:


The way exists, it is the HTML5 History API.

It needs JavaScript and HTML5 compliant browsers, or a javascript fallback for old IE (eg History.js).

Take a look at history.replaceState() and history.pushState() methods: the first alter the current history entry, the second adds a new one (creating noise in back button usage, so I suggest the first).

To remove the QueryString (the ?param1=value1&param2=value2 part) just run this script on page load:

<script>

    $(function(){
        history.replaceState("","",location.href.substring(0,location.href.indexOf("?")));
    });

</script>

While this client-side solution definitely improves clearness and eye candy, I doubt it improves security at all; Post-Redirect-Get would be better, but if you can't, then use this technique.

I generally use PRG in conjunction with this to achieve pretty URLs, and it works perfectly.

Note that this is a simulated PRG, an F5 after the page is loaded might have unpredictable behaviors according to how you've programmed your application.



来源:https://stackoverflow.com/questions/31644867/change-display-url-in-struts-2-to-hide-request-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!