carteruk carteruk - 1 year ago 264
HTML Question

Convert String to Integer JSP

I am a beginner using JSP. I want to display a list of incrementing integers using a maximum range of the users choice.

Entering: 6 should display the following:

  • number 1

  • number 2

  • number 3

  • number 4

  • number 5

  • number 6


<input type="number" name="numberMax" required>
<input type="submit" value="submit">


int numberMax = request.getParameter("numberMax"); // Cannot convert from String to int
for (int i = 1; i <= numberMax; i++)
{ %>
<li><%= i %></li>
<% } %>

How can I convert the input to an integer in order for the jsp scriptlet to print.

Answer Source

Try using this:

<%int no = Integer.parseInt(request.getParameter("numberMax"));%>

Its working for me.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download