public void service(ServletRequest request, ServletResponse response){ PrintWriter writer = ((HttpServletResponse) response)).getWriter(); writer.write("<html>"); writer.write("<body>"); writer.write("<table>"); for(int i=0; i<10; i++){ writer.write("<tr><td>"); writer.write("" + i); writer.write("</td></tr>"); } writer.write("</table>"); writer.write("</body>"); writer.write("</html>"); }
<html> <body> <table> <% for(int i=0; i<10; i++){ %><tr><td><%=i%></td></tr><% } %> </table> </body> </html>
As you can see, the JSP example is much shorter than the Servlet example, and it is much easier to get an overview of the HTML. However, this is not always the case. If you are working with an application with much domain logic, and little HTML, a servlet will perhaps be easier to use. If you have a lot of HTML and only a little logic here and there, JSP would probably be better suited for the task.
@reference_1_tutorials.jenkov.com
Java Web Application Technologies
No comments:
Post a Comment