0

I use a servlet to get values from database and I want to print that in jsp. My problem is the values are printed like usera userb userc. I want the output to be like

usera 
userb
userc

Please help me to do this. Here is what i have tried

<%
String Users=request.getParameter("Users");
String User[]=Users.trim().split(" ");
for(int i=0;i<User.length;i++){
    out.println(User[i]);
}
%>
Sumithra
  • 6,587
  • 19
  • 51
  • 50

2 Answers2

0

Since you are outputting html, you should add <br /> after each user:

 out.println(User[i] + "<br />");

Note that it is not advisable to use java code in JSPs. Write your java code in a servlet, place the results as request attributes, and then forward to a JSP, where you can show the result using JSTL.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
0
<%
String Users=request.getParameter("Users");
String User[]=Users.trim().split(" ");
for(int i=0;i<User.length;i++){
    out.println(User[i]+"<br/>");
}
%>

I would suggest you to go for JSTL

Here is how it should be :

Perform java code at servlet and forward request to a jsp file

Servlet :

String Users=request.getParameter("Users");
String User[]=Users.trim().split(" ");
request.setAttribute("name", User);

in that jsp file

<c:forEach var = "userName" items = "${name}">
<tr>
<font color="#000080"><td>${userName}</td></font>
</tr>
</c:forEach>  

See Also

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438