提交表单之前,停止用户更改html源中的值 [英] Stopping user to change values in html source before submitting form
问题描述
我有一个简单的html表单,如下所示:
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>
以下是我的 servlet
代码来读取get方法中的select值:
Following is my servlet
code to read the value of select in get method:
System.out.println("Value of select: "+ request.getParameter("mySelect"));
这很好,直到我更改了检查元素选项的值。在更改了inspect元素的值并提交了表单后,它发送了 Test
作为值 Two
而不是2 ,而不是 servlet
。
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?
推荐答案
没有什么可以阻止用户通过使用firebug /在浏览器中更改值检查元素/什么都可以。
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.
再次大喊大叫。
这篇关于提交表单之前,停止用户更改html源中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!