📜  Servlet 和 JSP 的区别

📅  最后修改于: 2022-05-13 01:54:47.259000             🧑  作者: Mango

Servlet 和 JSP 的区别

简单的介绍:
servlet是一个Java类,用于扩展托管通过请求-响应模型访问的应用程序的服务器的功能。 Servlet 主要用于扩展 Web 服务器托管的应用程序,但是它们也可以响应其他类型的请求。对于此类应用程序,特定于 HTTP 的 servlet 类由Java Servlet 技术定义。

JSP是一个文本文档,它包含两种类型的文本:静态数据和动态数据。静态数据可以用任何基于文本的格式(如 HTML、XML、SVG 和 WML)表示,动态内容可以用 JSP 元素表示。

Servlet 和 JSP 的区别

Servlet 和 JSP 的区别

ServletJSP
Servlet is a java code.JSP is a html based code.
Writing code for servlet is harder than JSP as it is html in java.JSP is easy to code as it is java in html.
Servlet plays a controller role in MVC approach.JSP is the view in MVC approach for showing output.
Servlet is faster than JSP.JSP is slower than Servlet because the first step in JSP lifecycle is the translation of JSP to java code and then compile.
Servlet can accept all protocol requests.JSP only accept http requests.
In Servlet, we can override the service() method.In JSP, we cannot override its service() method.
In Servlet by default session management is not enabled, user have to enable it explicitly.In JSP session management is automatically enabled.
In Servlet we have to implement everything like business logic and presentation logic in just one servlet file.In JSP business logic is separated from presentation logic by using javaBeans.
Modification in Servlet is a time consuming task because it includes reloading, recompiling and restarting the server.JSP modification is fast, just need to click the refresh button.

要详细了解它们,请阅读有关 Servlet 和 JSP 的这些文章。