Stopping user to change values in html source before submitting form

强颜欢笑 提交于 2019-12-02 11:54:44

问题


I have a simple html form as follows:

<form action="Test">
    <select name="mySelect">
        <option value="1">One</option>
        <option value="2">Two</option>
        <option value="3">Three</option>
        <option value="4">Four</option>
        <option value="5">Five</option>
    </select>
    <input type="submit" value="Submit">
</form>

Following is my servlet code to read the value of select in get method:

System.out.println("Value of select: "+ request.getParameter("mySelect"));

This works fine, until I change the value from inspect element option. After changing the value from inspect element, and submitting the form, it sends Test as a value of Two instead of 2, to servlet, which is not expected.

My question is that, Is there any way we can avoid this issue? or How to prevent client from sending incorrect data?


回答1:


There is nothing stopping a user from changing values in browser by using firebug/inspect element/ what ever..

What we can do is checking our values on server side and prompting user if they mismatch.

Shouting again ..

Never trust/depend on client....




回答2:


You can disable right click and the F12 button to prevent the issue. Follow the below links.

1.) Disable right click 2.) Disable F12 button



来源:https://stackoverflow.com/questions/25447188/stopping-user-to-change-values-in-html-source-before-submitting-form

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