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?
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....
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