Stopping user to change values in html source before submitting form

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.

enter image description here

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

5

2 Answers

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like