I’ve been working with a JSP+Java+Html, and I’ve encountered a problem with out.print() function, in a for cycle.
My function getGeneAvailableTaxonomies() returns a list of integer numbers (of type List<Integer>), and I want to print these numbers in an interface.
Here’s my code:
for(Integer i : ApplicationExtender.getApplicationExtender(application).getGeneAvailableTaxonomies())
{
out.print(String.format("<option value=\"%1$d\">%2$s</option>", i, TaxonId.getOrganismFromId(i)));
}
The doce %1$d should stand for the i integer value, while %2$s should stand for the other parameter, the taxonomy id value as String.
But, unfortunately, this is what appears:

While I would like to see something like:

There’s surely an error on my out.print() function call… but what’s wrong?
Many thanks
You dont need the “$” in your format String. As you may know, using scriptlets is not a good way to do Java Web Development. I think that using JSTL is far better, as you won’t mix Java code with markup in your JSP’s.
Edit: The printf method is not present in out object as I said earlier, since it is a JspWriter and JspWriter not inherit from PrintWriter (that have printf). Sorry. So, try this (it worked for me).
If you want to use a PrintWriter as in Servlets, so this will work: