🌈hello,你好鸭,我是Ethan,西安电子科技大学大三在读,很高兴你能来阅读。
✔️目前博客主要更新Java系列、项目案例、计算机必学四件套等。
🏃人生之义,在于追求,不在成败,勤通大道。加油呀!
🔥个人主页:Ethan Yankang
🔥推荐:史上最强八股文||一分钟看完我的几百篇博客
🔥温馨提示:划到文末发现专栏彩蛋 点击这里直接传送
🔥本篇概览:详细讲解了JavaWeb系列9——jsp的方方面面,包括底层运用转化等。🌈⭕🔥
【计算机领域一切迷惑的源头都是基本概念的模糊,算法除外】
🌈引言:
前一篇章:
8、JSP
8.1、什么是JSP
Java Server Pages : Java服务器端页面,也和Servlet一样,用于动态Web技术!
最大的特点:
- 写JSP就像在写HTML
区别:
- HTML只给用户提供静态的数据
- JSP页面中可以嵌入JAVA代码,为用户提供动态数据;
8.2、JSP原理
思路:JSP到底怎么执行的!
代码层面没有任何问题
服务器内部工作
这是Index.jsp的源码:
.jsp源码
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
下面查看他转化为的Java源码:
Tomcat中有一个work目录;
在我的tomcat下的目录中:
D:\Tomcat\apache-tomcat-9.0.91\work\Catalina\localhost\ROOT\org\apache\jsp
发现页面转化为java程序,显然这是java提供的底层支持,打开查看一下这个文件:
.java源码
/*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/9.0.91
* Generated at: 2024-07-19 02:53:45 UTC
* Note: The last modified time of this file was set to
* the last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent,
org.apache.jasper.runtime.JspSourceImports {
private static final javax.servlet.jsp.JspFactory _jspxFactory =
javax.servlet.jsp.JspFactory.getDefaultFactory();
private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;
private static final java.util.Set<java.lang.String> _jspx_imports_packages;
private static final java.util.Set<java.lang.String> _jspx_imports_classes;
static {
_jspx_imports_packages = new java.util.LinkedHashSet<>(4);
_jspx_imports_packages.add("javax.servlet");
_jspx_imports_packages.add("javax.servlet.http");
_jspx_imports_packages.add("javax.servlet.jsp");
_jspx_imports_classes = null;
}
private volatile javax.el.ExpressionFactory _el_expressionfactory;
private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.Map<java.lang.String,java.lang.Long> getDependants() {
return _jspx_dependants;
}
public java.util.Set<java.lang.String> getPackageImports() {
return _jspx_imports_packages;
}
public java.util.Set<java.lang.String> getClassImports() {
return _jspx_imports_classes;
}
public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
if (_el_expressionfactory == null) {
synchronized (this) {
if (_el_expressionfactory == null) {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
}
}
}
return _el_expressionfactory;
}
public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
if (_jsp_instancemanager == null) {
synchronized (this) {
if (_jsp_instancemanager == null) {
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
}
}
return _jsp_instancemanager;
}
public void _jspInit() {
}
public void _jspDestroy() {
}
public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException {
if (!javax.servlet.DispatcherType.ERROR.equals(request.getDispatcherType())) {
final java.lang.String _jspx_method = request.getMethod();
if ("OPTIONS".equals(_jspx_method)) {
response.setHeader("Allow","GET, HEAD, POST, OPTIONS");
return;
}
if (!"GET".equals(_jspx_method) && !"POST".equals(_jspx_method) && !"HEAD".equals(_jspx_method)) {
response.setHeader("Allow","GET, HEAD, POST, OPTIONS");
response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSP 只允许 GET、POST 或 HEAD。Jasper 还允许 OPTIONS");
return;
}
}
final javax.servlet.jsp.PageContext pageContext;
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
final java.lang.Object page = this;
javax.servlet.jsp.JspWriter _jspx_out = null;
javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
response.setContentType("text/html; charset=UTF-8");
pageContext = _jspxFactory.getPageContext(this, request, response,
null, false, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
out = pageContext.getOut();
_jspx_out = out;
out.write("\r\n");
out.write("\r\n");
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy");
request.setAttribute("year", sdf.format(new java.util.Date()));
request.setAttribute("tomcatUrl", "https://tomcat.apache.org/");
request.setAttribute("tomcatDocUrl", "/docs/");
request.setAttribute("tomcatExamplesUrl", "/examples/");
out.write("\r\n");
out.write("<!DOCTYPE html>\r\n");
out.write("<html lang=\"en\">\r\n");
out.write(" <head>\r\n");
out.write(" <meta charset=\"UTF-8\" />\r\n");
out.write(" <title>");
out.print(request.getServletContext().getServerInfo() );
out.write("</title>\r\n");
out.write(" <link href=\"favicon.ico\" rel=\"icon\" type=\"image/x-icon\" />\r\n");
out.write(" <link href=\"tomcat.css\" rel=\"stylesheet\" type=\"text/css\" />\r\n");
out.write(" </head>\r\n");
out.write("\r\n");
out.write(" <body>\r\n");
out.write(" <div id=\"wrapper\">\r\n");
out.write(" <div id=\"navigation\" class=\"curved container\">\r\n");
out.write(" <span id=\"nav-home\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("\">Home</a></span>\r\n");
out.write(" <span id=\"nav-hosts\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("\">Documentation</a></span>\r\n");
out.write(" <span id=\"nav-config\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("config/\">Configuration</a></span>\r\n");
out.write(" <span id=\"nav-examples\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatExamplesUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("\">Examples</a></span>\r\n");
out.write(" <span id=\"nav-wiki\"><a href=\"https://cwiki.apache.org/confluence/display/TOMCAT/\">Wiki</a></span>\r\n");
out.write(" <span id=\"nav-lists\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html\">Mailing Lists</a></span>\r\n");
out.write(" <span id=\"nav-help\"><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("findhelp.html\">Find Help</a></span>\r\n");
out.write(" <br class=\"separator\" />\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"asf-box\">\r\n");
out.write(" <h1>");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${pageContext.servletContext.serverInfo}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("</h1>\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"upper\" class=\"curved container\">\r\n");
out.write(" <div id=\"congrats\" class=\"curved container\">\r\n");
out.write(" <h2>If you're seeing this, you've successfully installed Tomcat. Congratulations!</h2>\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"notice\">\r\n");
out.write(" <img id=\"tomcat-logo\" src=\"tomcat.svg\" alt=\"[tomcat logo]\" />\r\n");
out.write(" <div id=\"tasks\">\r\n");
out.write(" <h3>Recommended Reading:</h3>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("security-howto.html\">Security Considerations How-To</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("manager-howto.html\">Manager Application How-To</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("cluster-howto.html\">Clustering/Session Replication How-To</a></h4>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"actions\">\r\n");
out.write(" <div class=\"button\">\r\n");
out.write(" <a class=\"container shadow\" href=\"/manager/status\"><span>Server Status</span></a>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"button\">\r\n");
out.write(" <a class=\"container shadow\" href=\"/manager/html\"><span>Manager App</span></a>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"button\">\r\n");
out.write(" <a class=\"container shadow\" href=\"/host-manager/html\"><span>Host Manager</span></a>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <br class=\"separator\" />\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"middle\" class=\"curved container\">\r\n");
out.write(" <h3>Developer Quick Start</h3>\r\n");
out.write(" <div class=\"col25\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <p><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("setup.html\">Tomcat Setup</a></p>\r\n");
out.write(" <p><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("appdev/\">First Web Application</a></p>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col25\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <p><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("realm-howto.html\">Realms & AAA</a></p>\r\n");
out.write(" <p><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("jndi-datasource-examples-howto.html\">JDBC DataSources</a></p>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col25\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <p><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatExamplesUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("\">Examples</a></p>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col25\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <p><a href=\"https://cwiki.apache.org/confluence/display/TOMCAT/Specifications\">Servlet Specifications</a></p>\r\n");
out.write(" <p><a href=\"https://cwiki.apache.org/confluence/display/TOMCAT/Tomcat+Versions\">Tomcat Versions</a></p>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <br class=\"separator\" />\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"lower\">\r\n");
out.write(" <div id=\"low-manage\" class=\"\">\r\n");
out.write(" <div class=\"curved container\">\r\n");
out.write(" <h3>Managing Tomcat</h3>\r\n");
out.write(" <p>For security, access to the <a href=\"/manager/html\">manager webapp</a> is restricted.\r\n");
out.write(" Users are defined in:</p>\r\n");
out.write(" <pre>$CATALINA_HOME/conf/tomcat-users.xml</pre>\r\n");
out.write(" <p>In Tomcat 9.0 access to the manager application is split between\r\n");
out.write(" different users. <a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("manager-howto.html\">Read more...</a></p>\r\n");
out.write(" <br />\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("RELEASE-NOTES.txt\">Release Notes</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("changelog.html\">Changelog</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("migration.html\">Migration Guide</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("security.html\">Security Notices</a></h4>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"low-docs\" class=\"\">\r\n");
out.write(" <div class=\"curved container\">\r\n");
out.write(" <h3>Documentation</h3>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("\">Tomcat 9.0 Documentation</a></h4>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("config/\">Tomcat 9.0 Configuration</a></h4>\r\n");
out.write(" <h4><a href=\"https://cwiki.apache.org/confluence/display/TOMCAT/\">Tomcat Wiki</a></h4>\r\n");
out.write(" <p>Find additional important configuration information in:</p>\r\n");
out.write(" <pre>$CATALINA_HOME/RUNNING.txt</pre>\r\n");
out.write(" <p>Developers may be interested in:</p>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"https://tomcat.apache.org/bugreport.html\">Tomcat 9.0 Bug Database</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("api/index.html\">Tomcat 9.0 JavaDocs</a></li>\r\n");
out.write(" <li><a href=\"https://github.com/apache/tomcat/tree/9.0.x\">Tomcat 9.0 Git Repository at GitHub</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"low-help\" class=\"\">\r\n");
out.write(" <div class=\"curved container\">\r\n");
out.write(" <h3>Getting Help</h3>\r\n");
out.write(" <h4><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("faq/\">FAQ</a> and <a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html\">Mailing Lists</a></h4>\r\n");
out.write(" <p>The following mailing lists are available:</p>\r\n");
out.write(" <ul>\r\n");
out.write(" <li id=\"list-announce\"><strong><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html#tomcat-announce\">tomcat-announce</a><br />\r\n");
out.write(" Important announcements, releases, security vulnerability notifications. (Low volume).</strong>\r\n");
out.write(" </li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html#tomcat-users\">tomcat-users</a><br />\r\n");
out.write(" User support and discussion\r\n");
out.write(" </li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html#taglibs-user\">taglibs-user</a><br />\r\n");
out.write(" User support and discussion for <a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("taglibs/\">Apache Taglibs</a>\r\n");
out.write(" </li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html#tomcat-dev\">tomcat-dev</a><br />\r\n");
out.write(" Development mailing list, including commit messages\r\n");
out.write(" </li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <br class=\"separator\" />\r\n");
out.write(" </div>\r\n");
out.write(" <div id=\"footer\" class=\"curved container\">\r\n");
out.write(" <div class=\"col20\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <h4>Other Downloads</h4>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("download-connectors.cgi\">Tomcat Connectors</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("download-native.cgi\">Tomcat Native</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("taglibs/\">Taglibs</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("deployer-howto.html\">Deployer</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col20\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <h4>Other Documentation</h4>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("connectors-doc/\">Tomcat Connectors</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("connectors-doc/\">mod_jk Documentation</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("native-doc/\">Tomcat Native</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatDocUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("deployer-howto.html\">Deployer</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col20\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <h4>Get Involved</h4>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("getinvolved.html\">Overview</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("source.html\">Source Repositories</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("lists.html\">Mailing Lists</a></li>\r\n");
out.write(" <li><a href=\"https://cwiki.apache.org/confluence/display/TOMCAT/\">Wiki</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col20\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <h4>Miscellaneous</h4>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("contact.html\">Contact</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("legal.html\">Legal</a></li>\r\n");
out.write(" <li><a href=\"https://www.apache.org/foundation/sponsorship.html\">Sponsorship</a></li>\r\n");
out.write(" <li><a href=\"https://www.apache.org/foundation/thanks.html\">Thanks</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <div class=\"col20\">\r\n");
out.write(" <div class=\"container\">\r\n");
out.write(" <h4>Apache Software Foundation</h4>\r\n");
out.write(" <ul>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("whoweare.html\">Who We Are</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("heritage.html\">Heritage</a></li>\r\n");
out.write(" <li><a href=\"https://www.apache.org\">Apache Home</a></li>\r\n");
out.write(" <li><a href=\"");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${tomcatUrl}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write("resources.html\">Resources</a></li>\r\n");
out.write(" </ul>\r\n");
out.write(" </div>\r\n");
out.write(" </div>\r\n");
out.write(" <br class=\"separator\" />\r\n");
out.write(" </div>\r\n");
out.write(" <p class=\"copyright\">Copyright ©1999-");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate("${year}", java.lang.String.class, (javax.servlet.jsp.PageContext)_jspx_page_context, null));
out.write(" Apache Software Foundation. All Rights Reserved</p>\r\n");
out.write(" </div>\r\n");
out.write(" </body>\r\n");
out.write("\r\n");
out.write("</html>\r\n");
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try {
if (response.isCommitted()) {
out.flush();
} else {
out.clearBuffer();
}
} catch (java.io.IOException e) {}
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
else throw new ServletException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}
显然jsp底层还是html语言的操作,比如:
但是他还支持的是动态数据的提供。
总结
浏览器向服务器发送请求,不管访问什么资源,其实都是在访问Servlet!
JSP最终也会被转换成为一个Java类!
JSP 本质上就是一个Servlet
//初始化
public void _jspInit() {
}
//销毁
public void _jspDestroy() {
}
//JSPService
public void _jspService(.HttpServletRequest request,HttpServletResponse response)
-
判断请求
-
内置一些对象
final javax.servlet.jsp.PageContext pageContext; //页面上下文
javax.servlet.http.HttpSession session = null; //session
final javax.servlet.ServletContext application; //applicationContext
final javax.servlet.ServletConfig config; //config
javax.servlet.jsp.JspWriter out = null; //out
final java.lang.Object page = this; //page:当前
HttpServletRequest request //请求
HttpServletResponse response //响应
3.输出页面前增加的代码
response.setContentType("text/html"); //设置响应的页面类型
pageContext = _jspxFactory.getPageContext(this, request, response,
null, true, 8192, true);
_jspx_page_context = pageContext;
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
_jspx_out = out;
4.以上的这些个对象我们可以在JSP页面中直接使用!
在JSP页面中;
只要是 JAVA代码就会原封不动的输出;
如果是HTML代码,就会被转换为:
out.write("<html>\r\n");
这样的格式,输出到前端!
8.3、JSP基础语法 任何语言都有自己的语法,JAVA中有。 JSP 作为java技术的一种应用,它拥有一些自己扩充的语法(了解,知道即可!),Java所有语法都支持!
8.3.1、JSP表达式
这些内容直接请访问:B站---【狂神说Java】JavaWeb入门到实战---笔记-CSDN博客
💖💖💖💖💖💖💖💖💖💖💖💖💖💖💖💖💖💖
热门专栏推荐
🌈🌈计算机科学入门系列 关注走一波💕💕
🌈🌈CSAPP深入理解计算机原理 关注走一波💕💕
🌈🌈微服务项目之黑马头条 关注走一波💕💕
🌈🌈redis深度项目之黑马点评 关注走一波💕💕
🌈🌈JAVA面试八股文系列专栏 关注走一波💕💕
🌈🌈JAVA基础试题集精讲 关注走一波💕💕
🌈🌈代码随想录精讲200题 关注走一波💕💕
总栏
🌈🌈JAVA基础要夯牢 关注走一波💕💕
🌈🌈JAVA后端技术栈 关注走一波💕💕
🌈🌈JAVA面试八股文 关注走一波💕💕
🌈🌈JAVA项目(含源码深度剖析) 关注走一波💕💕
🌈🌈计算机四件套 关注走一波💕💕
🌈🌈数据结构与算法 关注走一波💕💕
🌈🌈必知必会工具集 关注走一波💕💕
🌈🌈书籍网课笔记汇总 关注走一波💕💕
📣非常感谢你阅读到这里,如果这篇文章对你有帮助,希望能留下你的点赞👍 关注❤收藏✅ 评论💬,大佬三连必回哦!thanks!!!
📚愿大家都能学有所得,功不唐捐!