Difference between Java Servlet and JSP
Servlet is html in java whereas JSP is java in html. Servlets run faster compared to JSP. … JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content. In MVC, jsp acts as a view and servlet acts as a controller.
Servlet example: Hello.java
response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.println("<html>"); writer.println("<head>"); writer.println("<title>This is my .java file to .class file. Sample Application Servlet Page</title>"); writer.println("</head>"); writer.println("<body bgcolor=white>"); writer.println("<table border=\"0\">"); writer.println("<tr>"); writer.println("<td>"); writer.println("<img src=\"images/tomcat.gif\">"); writer.println("</td>"); writer.println("<td>"); writer.println("<h1>Sample Application Servlet</h1>"); writer.println("This is the output of a servlet that is part of"); writer.println("the Hello, World application."); writer.println("</td>"); writer.println("</tr>"); writer.println("</table>");
JSP example: hello.jsp
<table border="0"> <tr> <td align=center> <img src="images/tomcat.gif"> </td> <td> <h1><%= new String("Sample Application JSP Page") %></h1> This is the output of a JSP page that is part of the Hello, World application. </td> </tr> </table>