Reputation: 624
In PHP Page, to print array, I use print_r(); In jsp, to print string, out.print() is used. for example :
<?php print_r($_POST); ?>
was is equal in jsp??? How can I print array values in jsp?
Upvotes: 1
Views: 1858
Reputation: 401
you can try
ObjectMapper mapper = new ObjectMapper();
System.out.println( mapper.defaultPrettyPrintingWriter().writeValueAsString(myList) );
myList is your array varible .
or for post data try
Map<String, String[]> parameters = request.getParameterMap();
for(String parameter : parameters.keySet()) {
if(parameter.toLowerCase().startsWith("your object name in html")) {
String[] values = parameters.get(parameter);
//your code here
}
}
and import java.util.Map
Upvotes: 1
Reputation: 53525
@todayslate gave a good answer, only that you have to know the length of the array for that. Now, of course that you can just check the length (by colors.length
), but I find it more appealing to do:
String[] colors = {"red", "green", "blue"};
//suppose you have no idea how many colors are in the
//array since you received it from another method or something
for (String color: colors) {
out.print("<P>" + color + "</p>");
}
Upvotes: 0
Reputation: 8771
You could to something like this :
<%
out.println(StringUtils.join(variable,"<br />");
%>
If you actually want to print POST variables, follow this link :
Get all parameters from JSP page
Upvotes: 0
Reputation: 2833
Use a for loop
String[] colors = {"red", "green", "blue"};
for (int i = 0; i < colors.length; i++) {
out.print("<P>" + colors[i] + "</p>");
}
Upvotes: 0