Why jsp?

时间:2022-08-01 08:16:22

Before the JSP come into the world . The CGI and servlet took the responsibility of generating dynamic content for Http Request.

So why JSP? It there any reason for replacing CGI and Servlet ways with JSP ?

For CGI and Servlet we knew the secret of dynamic content , It is that they can output the raw html to the client.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
.....
PrintWriter out=reponse.getWriter();
out.Println("<html>.......</html>");
....
}

  So if there is a way to combine the html and java code into a Servlet class . It will be good. The developer can edit html for static content.

and let java code to generate dynamic content. So the JSP was born. Actually the JSP will be compiled to a class. and the class is inheritted from HttpServlet.