0

I need to display variables that were initialized in a JSP page.

I have already tried to use ${value} and I also already tried everything in that was suggested in this thread: Values not displayed in jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
````<head>
````````<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
````````<title>JSP Page</title>
````</head>
````<body>
````````<h1>Hello World!</h1>
````````<ul>
````````````<% for(int i=0;i<10;i++){ %>
````````````<li>${i}</li> <!--I want to display i-->
````````````<% } %>
````````</ul>
````</body>
</html>

I expect the page:

<h1>Hello World!</h1>
<ul>
<li>0</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>

I get the page:

<h1>Hello World!</h1>
<ul>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>

2 Answers2

0

try something like this:

<%int number=Integer.parseInt(a);
for(int i=1;i<number;i++)
{
%>
Eagle95
  • 36
  • 7
0

Try using scriplets, these are not encouraged nowadays but it can still get the work done.

<% for(int i=0;i<10;i++){ %>
    <li><%=i%></li>
<% } %>
Farhan Qasim
  • 990
  • 5
  • 18