JavaWeb早期 :applet + servlet,
其中servlet中需要大量的response.getWriter().println("<html>");
JavaWeb 后期,JSP,只需要在html直接添加动态信息,即可。
什么是JSP
html + java代码 + jsp动态标签 = jsp;
JSP 真身 Servlet
当客户请求JSP页面时, 服务器会查看JSP对应的Servlet是否存在,
如果存在,那么直接调用Servlet的service方法来处理请求
如果不存在, 那么服务器会将JSP编译成Java,再把java编译成class,然后再调用service()
当JSP页面二次处理请求时,就会直接用真身的service();
demo
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" +request.getServerName() +":"+request.getServerPort() + path + "/";
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2">
<meta http-equiv="description" content="This is my page">
</head>
<body>
This is my JSP page. <br>
</body>
</html>
网友评论