Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

jspResult.jsp

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

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

like image 944
carteruk Avatar asked Dec 04 '22 04:12

carteruk


1 Answers

Try using this:

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

Its working for me.

like image 107
Megha Sharma Avatar answered Dec 19 '22 01:12

Megha Sharma