list of users in servlet
import java.io.IOException;
+import java.io.PrintWriter;
import java.util.List;
import javax.ejb.EJB;
@@ -20,14 +21,27 @@ public class TestEJBServlet extends HttpServlet {
@EJB
private UserBeanLocal userBean;
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
List<User> users = userBean.getUsers();
- response.getWriter()
- .append("The number of users is: " + users.size());
+ PrintWriter out = response.getWriter();
+
+ out.println("<html>");
+ out.println("<head><title>Users</title></head>");
+ out.println("<body>");
+ out.println("<center><h1>List of users:</h1>");
+ out.println("<table border=\"1\" align=\"center\" style=\"width:50%\">");
+ for (User user : users) {
+ out.println("<tr>");
+ out.print("<td>" + user.getUsername() + "</td>");
+ out.print("<td>" + user.getEmail() + "</td>");
+ out.println("</tr>");
+ }
}
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
doGet(request, response);
}
}
