javawebä¹jspæä»¤
1.JSPæä»¤ç®ä»
JSPæä»¤æ¯ä¸ºJSPå¼æè®¾è®¡çï¼å®ä»¬å¹¶ä¸ç´æ¥äº§çä»»ä½å¯è§è¾åºï¼èåªæ¯åè¯å¼æå¦ä½å¤çJSP页é¢ä¸çå ¶ä½é¨åã
å¨JSP 2.0è§èä¸å ±å®ä¹äºä¸ä¸ªæä»¤ï¼pageæä»¤ï¼Includeæä»¤ï¼taglibæä»¤ã
JSPæä»¤çåºæ¬è¯æ³æ ¼å¼ï¼<%@ æä»¤ 屿§å="å¼" %>
ä¾å¦ï¼
<%@ page contentType="text/html;charset=gb2312"%>
妿ä¸ä¸ªæä»¤æå¤ä¸ªå±æ§ï¼è¿å¤ä¸ªå±æ§å¯ä»¥åå¨ä¸ä¸ªæä»¤ä¸ï¼ä¹å¯ä»¥åå¼åã
ä¾å¦ï¼
<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.util.Date"%>
ä¹å¯ä»¥åä½ï¼
<%@ page contentType="text/html;charset=gb2312" import="java.util.Date"%>
2.pageæä»¤
pageæä»¤ç¨äºå®ä¹JSP页é¢çåç§å±æ§ï¼æ 论pageæä»¤åºç°å¨JSP页é¢ä¸çä»ä¹å°æ¹ï¼å®ä½ç¨ç齿¯æ´ä¸ªJSP页é¢ï¼ä¸ºäºä¿æç¨åºçå¯è¯»æ§åéµå¾ªè¯å¥½çç¼ç¨ä¹ æ¯ï¼pageæä»¤æå¥½æ¯æ¾å¨æ´ä¸ªJSP页é¢çèµ·å§ä½ç½®ã
JSP 2.0è§èä¸å®ä¹çpageæä»¤ç宿´è¯æ³ï¼
<%@ page [ language="java" ] [ extends="package.class" ] [ import="{package.class | package.*}, ..." ] [ session="true | false" ] [ buffer="none | 8kb | sizekb" ] [ autoFlush="true | false" ] [ isThreadSafe="true | false" ] [ info="text" ] [ errorPage="relative_url" ] [ isErrorPage="true | false" ] [ contentType="mimeType [ ;charset=characterSet ]" | "text/html ; charset=ISO-8859-1" ] [ pageEncoding="characterSet | ISO-8859-1" ] [ isELIgnored="true | false" ] %>
2.1 import屿§
å¨jsp页é¢ä¸ï¼jsp弿ä¼èªå¨å¯¼å ¥ä¸é¢çå åç±»ï¼
java.lang.*
javax.servlet.*
javax.servlet.jsp.*
javax.servlet.http.*
å¯ä»¥å¨ä¸æ¡pageæä»¤å¼å ¥å¤ä¸ªç±»åå ï¼å ¶ä¸çæ¯ä¸ªå åç±»ä¹é´ä½¿ç¨éå·åéå¼ï¼ä¾å¦ï¼
<%@ page import="java.util.Date,java.sql.*,java.io.*"%>
2.2 errorPage屿§
- errorPage屿§ç设置å¼å¿ 须使ç¨ç¸å¯¹è·¯å¾ï¼å¦æä»¥â/âå¼å¤´ï¼è¡¨ç¤ºç¸å¯¹äºå½åWebåºç¨ç¨åºçæ ¹ç®å½(注æä¸æ¯ç«ç¹æ ¹ç®å½)ï¼å¦åï¼è¡¨ç¤ºç¸å¯¹äºå½å页é¢ã
- å¯ä»¥å¨web.xmlæä»¶ä¸ä½¿ç¨<error-page>å ç´ ä¸ºæ´ä¸ªWebåºç¨ç¨åºè®¾ç½®é误å¤ç页é¢ã
- <error-page>å ç´ æ3个åå ç´ ï¼<error-code>ã<exception-type>ã<location>
- <error-code>åå ç´ æå®é误çç¶æç ï¼ä¾å¦ï¼<error-code>404</error-code>
- <exception-type>åå ç´ æå®å¼å¸¸ç±»çå®å ¨éå®åï¼ä¾å¦ï¼<exception-type>java.lang.ArithmeticException</exception-type>
- <location>åå ç´ æå®ä»¥â/âå¼å¤´çé误å¤ç页é¢çè·¯å¾ï¼ä¾å¦ï¼<location>/ErrorPage/404Error.jsp</location>
- å¦æè®¾ç½®äºæä¸ªJSP页é¢çerrorPage屿§ï¼é£ä¹å¨web.xmlæä»¶ä¸è®¾ç½®çé误å¤çå°ä¸å¯¹è¯¥é¡µé¢èµ·ä½ç¨ã
jsperrorPageçç¸å¯¹è·¯å¾ï¼â/â表示å½åwebåºç¨ç¨åºçæ ¹ç®å½ï¼WebRootï¼ï¼â./â代表å½åç®å½ï¼å³å½åæä»¶æå¨çç®å½ï¼ï¼â../â代表å½åæä»¶æå¨ç®å½çä¸ä¸çº§ç®å½ã
ä¾å¦æä»¥ä¸çå·¥ç¨ç®å½ç»æï¼
testA.jspä¸pageæä»¤çerrorPageè·¯å¾ä¸ºï¼
<%@ page import="java.util.Date" errorPage="/jspTest/error.jsp"%>
å³è·¯å¾"/jspTest/error.jsp"为âWebRoot/jspTest/error.jspâã
使ç¨errorPage屿§å¯ä»¥ææåºéå跳转çé误页é¢ï¼æ¯å¦å¦ä¸çtestA.jsp代ç ï¼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.util.Date" errorPage="/jspTest/error.jsp"%> <% 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 'testA.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,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% int i=2/0; %> </body> </html>
int i=2/0ï¼æ¾ç¶åºéï¼ç¬¬äºè¡pageæä»¤çerrorPage屿§<%@ page import="java.util.Date" errorPage="/jspTest/error.jsp"%>ææåºéå跳转å°error.jspæä»¶ï¼error.jspçå 容为ï¼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%@ page import="java.io.PrintWriter" %> <% 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 'error.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,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <% PrintWriter outs=response.getWriter(); outs.write("åºéå¦!"); %> </body> </html>
è¿è¡ç»æå¦ä¸ï¼
2.3 å¨web.xmlä¸ä½¿ç¨<error-page>æ ç¾ä¸ºæ´ä¸ªwebåºç¨è®¾ç½®é误å¤ç页é¢
ä¾å¦ï¼ä½¿ç¨<error-page>æ ç¾é ç½®é对404é误çå¤ç页é¢ï¼å¨web.xmlä¸çé ç½®å¦ä¸ï¼
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- é对404é误çå¤çé¡µé¢ --> <error-page> <error-code>404</error-code> <location>/jspTest/error.jsp</location> </error-page> </web-app>
è¦è·³è½¬çerror.jspç代ç å¦ä¸ï¼
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <html> <head> <title>404é误å好æç¤ºé¡µé¢</title> <!-- 3ç§éåèªå¨è·³è½¬åé¦é¡µ --> <meta http-equiv="refresh" content="3;url=${pageContext.request.contextPath}/WEB-INF/index.jsp"> </head> <body> <p>404é误</p> <br/> 3ç§éåèªå¨è·³è½¬åé¦é¡µï¼å¦ææ²¡æè·³è½¬ï¼è¯·ç¹å»<a href="${pageContext.request.contextPath}/index.jsp">è¿é</a> </body> </html>
å½è®¿é®ä¸ä¸ªä¸åå¨çwebèµæºæ¶ï¼å°±ä¼è·³è½¬å°å¨web.xmlä¸é ç½®ç404é误å¤ç页é¢error.jspï¼
2.4 使ç¨isErrorPage屿§æ¾ç¤ºå£°æé¡µé¢ä¸ºé误
妿æä¸ä¸ªjsp页颿¯ä½ä¸ºç³»ç»çé误å¤ç页é¢ï¼é£ä¹å»ºè®®å°pageæä»¤çisErrorPage屿§ï¼é»è®¤ä¸ºfalseï¼è®¾ç½®ä¸ºâtrueâæ¥æ¾ç¤ºå£°æè¿ä¸ªjsp页颿¯ä¸ä¸ªé误å¤ç页é¢ãå°error.jsp页颿¾å¼å£°æä¸ºé误å¤ç页é¢åï¼å¥½å¤å°±æ¯Jsp弿å¨å°jsp页é¢ç¿»è¯æServletçæ¶åï¼å¨Servletç _jspServiceæ¹æ³ä¸ä¼å£°æä¸ä¸ªexception对象ï¼ç¶åå°è¿è¡jspåºéçå¼å¸¸ä¿¡æ¯åå¨å°exception对象ä¸ï¼ç±äºServletç_jspServiceæ¹æ³ä¸å£°æäºexception对象ï¼é£ä¹å°±å¯ä»¥å¨error.jsp页é¢ä¸ä½¿ç¨exception对象ï¼è¿æ ·å°±å¯ä»¥å¨Jsp页é¢ä¸æ¿å°åºéçå¼å¸¸ä¿¡æ¯äºãå¦ææ²¡æè®¾ç½®isErrorPage="true"ï¼é£ä¹å¨jsp页é¢ä¸æ¯æ æ³ä½¿ç¨exception对象çã
è¥æå®isErrorPage=âtrueâï¼å¹¶ä½¿ç¨exceptionçæ¹æ³äºï¼ä¸è¬ä¸å»ºè®®è½å¤ç´æ¥è®¿é®è¯¥é¡µé¢ï¼èåªä½ä¸ºè¯·æ±è½¬åçæ¹å¼è®¿é®ã
Jspæ9大å 置对象ï¼èä¸è¬æ åµä¸exception对象å¨Jsp页é¢ä¸æ¯è·åä¸å°çï¼åªæè®¾ç½®pageæä»¤isErrorPage屿§ä¸ºâtrueâæ¥æ¾ç¤ºå£°æä¸ä¸ªjsp页颿¯ä¸ä¸ªé误å¤ç页é¢ä¹åæè½å¤å¨jsp页é¢ä¸ä½¿ç¨exception对象ã
3.includeæä»¤
å¨JSPä¸å¯¹äºå 嫿䏤ç§è¯å¥å½¢å¼ï¼@includeæä»¤å<jsp:include>æä»¤
3.1 @includeæä»¤
includeæä»¤ç¨äºå¼å ¥å ¶å®JSP页é¢ï¼å¦æä½¿ç¨includeæä»¤å¼å ¥äºå ¶å®JSP页é¢ï¼é£ä¹JSP弿尿è¿ä¸¤ä¸ªJSPç¿»è¯æä¸ä¸ªservletãæä»¥includeæä»¤å¼å ¥é常ä¹ç§°ä¹ä¸ºéæå¼å ¥ã
è¯æ³ï¼<%@ include file="relativeURL"%>ï¼å ¶ä¸çfile屿§ç¨äºæå®è¢«å¼å ¥æä»¶çè·¯å¾ãè·¯å¾ä»¥â/âå¼å¤´ï¼è¡¨ç¤ºä»£è¡¨å½åwebåºç¨ã
ä¾å¦ï¼
includeTest1.jsp
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <% String path1 = request.getContextPath(); String basePath1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path1+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath1%>"> <title>My JSP 'includeTest.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,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <h2>"includeTest1.jsp's content"</h2> <%@ include file="includeTest2.jsp" %> </body> </html>
includeTest2.jsp
<%@ 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 'includeTest2.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,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <h2>"includeTest2.jsp's content"</h2> </body> </html>
includeTest1.jsp使ç¨<%@ include file="includeTest2.jsp" %>å°includeTest2.jspå 容å å«è¿å»ï¼ç±äºinclude伿¶åå°ä¸¤ä¸ªjsp页é¢ï¼å¹¶ä¼æä¸¤ä¸ªjspç¿»è¯æä¸ä¸ªservletï¼æä»¥è¿ä¸¤ä¸ªjspçæä»¤ï¼é¤pageEncodingåimportä¹å¤ï¼ä»¥åå®ä¹çåéåä¸è½éå¤ãå°¤å ¶æ³¨ææ°å»ºjspæä»¶åæç代ç ä¸çString pathåString basePathï¼è¦æ³¨æä¿®æ¹å ¶ä¸çä¸ä¸ªjspæä»¶çåéåï¼å¦åä¼åºç°åéåéå¤å®ä¹çé误ãå¦ä¸å°±æ¯include includeTest2.jspä¹åè½¬æ¢æçincludeTest1_jspç±»çæºä»£ç ã
/* * Generated by the Jasper component of Apache Tomcat * Version: Apache Tomcat/8.5.9 * Generated at: 2018-10-20 13:08:44 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.jspTest; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import java.util.*; import java.util.*; public final class includeTest1_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; static { _jspx_dependants = new java.util.HashMap<java.lang.String,java.lang.Long>(1); _jspx_dependants.put("/jspTest/includeTest2.jsp", Long.valueOf(1540040843018L)); } 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.HashSet<>(); _jspx_imports_packages.add("javax.servlet"); _jspx_imports_packages.add("java.util"); _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 { final java.lang.String _jspx_method = request.getMethod(); if (!"GET".equals(_jspx_method) && !"POST".equals(_jspx_method) && !"HEAD".equals(_jspx_method) && !javax.servlet.DispatcherType.ERROR.equals(request.getDispatcherType())) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSPs only permit GET POST or HEAD"); return; } final javax.servlet.jsp.PageContext pageContext; javax.servlet.http.HttpSession session = null; 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=ISO-8859-1"); 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; out.write('\r'); out.write('\n'); String path1 = request.getContextPath(); String basePath1 = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path1+"/"; out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" <base href=\""); out.print(basePath1); out.write("\">\r\n"); out.write(" \r\n"); out.write(" <title>My JSP 'includeTest.jsp' starting page</title>\r\n"); out.write(" \r\n"); out.write("\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n"); out.write("\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n"); out.write("\t<!--\r\n"); out.write("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">\r\n"); out.write("\t-->\r\n"); out.write("\r\n"); out.write(" <script>\"undefined\"==typeof CODE_LIVE&&(!function(e){var t={nonSecure:\"51550\",secure:\"51555\"},c={nonSecure:\"http://\",secure:\"https://\"},r={nonSecure:\"127.0.0.1\",secure:\"gapdebug.local.genuitec.com\"},n=\"https:\"===window.location.protocol?\"secure\":\"nonSecure\";script=e.createElement(\"script\"),script.type=\"text/javascript\",script.async=!0,script.src=c[n]+r[n]+\":\"+t[n]+\"/codelive-assets/bundle.js\",e.getElementsByTagName(\"head\")[0].appendChild(script)}(document),CODE_LIVE=!0);</script></head>\r\n"); out.write(" \r\n"); out.write(" <body data-genuitec-lp-enabled=\"false\" data-genuitec-file-id=\"wc1-8\" data-genuitec-path=\"/MyWebProject/WebRoot/jspTest/includeTest1.jsp\">\r\n"); out.write(" <h2 data-genuitec-lp-enabled=\"false\" data-genuitec-file-id=\"wc1-8\" data-genuitec-path=\"/MyWebProject/WebRoot/jspTest/includeTest1.jsp\">\"includeTest1.jsp's content\"</h2>\r\n"); out.write(" "); out.write('\r'); out.write('\n'); String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; out.write("\r\n"); out.write("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" <base href=\""); out.print(basePath); out.write("\">\r\n"); out.write(" \r\n"); out.write(" <title>My JSP 'includeTest2.jsp' starting page</title>\r\n"); out.write(" \r\n"); out.write("\t<meta http-equiv=\"pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t<meta http-equiv=\"keywords\" content=\"keyword1,keyword2,keyword3\">\r\n"); out.write("\t<meta http-equiv=\"description\" content=\"This is my page\">\r\n"); out.write("\t<!--\r\n"); out.write("\t<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">\r\n"); out.write("\t-->\r\n"); out.write("\r\n"); out.write(" <script>\"undefined\"==typeof CODE_LIVE&&(!function(e){var t={nonSecure:\"51550\",secure:\"51555\"},c={nonSecure:\"http://\",secure:\"https://\"},r={nonSecure:\"127.0.0.1\",secure:\"gapdebug.local.genuitec.com\"},n=\"https:\"===window.location.protocol?\"secure\":\"nonSecure\";script=e.createElement(\"script\"),script.type=\"text/javascript\",script.async=!0,script.src=c[n]+r[n]+\":\"+t[n]+\"/codelive-assets/bundle.js\",e.getElementsByTagName(\"head\")[0].appendChild(script)}(document),CODE_LIVE=!0);</script></head>\r\n"); out.write(" \r\n"); out.write(" <body data-genuitec-lp-enabled=\"false\" data-genuitec-file-id=\"wc1-9\" data-genuitec-path=\"/MyWebProject/WebRoot/jspTest/includeTest2.jsp\">\r\n"); out.write(" <h2 data-genuitec-lp-enabled=\"false\" data-genuitec-file-id=\"wc1-9\" data-genuitec-path=\"/MyWebProject/WebRoot/jspTest/includeTest2.jsp\">\"includeTest2.jsp's content\"</h2>\r\n"); out.write(" </body>\r\n"); out.write("</html>\r\n"); out.write("\r\n"); out.write(" </body>\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); } } }
å¯ä»¥çå°ï¼includeTest1.jspåincludeTest2.jsp页é¢çå 容é½ä½¿ç¨out.writeè¾åºå°æµè§å¨äºãè¿è¡includeTest1.jspåï¼æ¾ç¤ºå¦ä¸çç»æï¼
使ç¨@includeå¯ä»¥å å«ä»»æçå å®¹ï¼æä»¶çåç¼æ¯ä»ä¹é½æ æè°ãè¿ç§æå«çæä»¶å 容å å«å°èªèº«é¡µé¢ç@includeè¯å¥å°±å«ä½éæå å«ï¼ä½ç¨åªæ¯æå«ç页é¢å 容å å«è¿æ¥ï¼å±äºéæå å«ã
3.2 jsp:includeæä»¤
æ¥jspæ ç¾ã