pragmus
pragmus

Reputation: 4063

Incorrect sending values from html form to java

I write servlet. I have such field in the forms:

<p>
   Car size: <input type="number" name="car_size" min = "2" max = "5" step = "1" value = "2" required/>
</p>

For example I've entered 2 figure. Then in java code I want to write this value in Integer variable:

Integer carSize = request.getIntHeader("car_size");

But then I see in that variable carSize -1 value. How to fix it?

Upvotes: 1

Views: 64

Answers (1)

Roman C
Roman C

Reputation: 1

To get the parameter from the request

Integer carSize = Integer.valueOf(request.getParameter("car_size"));

To make a request you should wrap the input field with a form tag and use this form to submit data in input fields.

Upvotes: 2

Related Questions