public void _jspInit();//初始化
public void _jspDestroy();//销毁
public void _jspService(request,response);//JSPService
final javax.servlet.jsp.PageContext pageContext; //页面上下文
javax.servlet.http.HttpSession session = null; //Session
final javax.servlet.ServletContext application;
final javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
HttpServletRequest request; //请求
HTTPServletResponse response; //响应
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;
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.3</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl-api -->
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
</dependencies>
注释:<%--xxx--%>
JSP表达式:<%=变量或表达式%>
,将程序的结果输出到客户端
JSP脚本片段:<% Java代码,可以使用JSP内置对象 %>
JSP声明:<%! service方法外的类中的代码 %>
<%@ page...%>
,设置页面参数,导入java包等<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page @improt... %>
设置错误页面
<%@ page isErrorPage="true" %>
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>
通用页面:header、footer等,通过include导入
<%@include file="common/header.jsp"%> <%--将两个页面合二为一,直接是out.write()--%>
<jsp:include page="/commen/footer.jsp"/> <%--通过java方法拼接页面,内外变量互不影响--%>
setAttribute("name", "value"),不同对象作用域不同
pageContext.findAttribute("name"):作用域从底层到高层寻找
pageContext.setAttribute("name", "value", scope):
${param.参数名}
<jsp:include page="index.jsp"></jsp:include>
<jsp:forward page="index.jsp">
<jsp:param name="key1" value="value1"/>
<jsp:param name="key2" value="value2"/>
</jsp:forward>
<%=request.getParameter("key")>
取参数为了HTML标签的补足,自定义了许多标签,标签的功能和Java代码一样
核心标签、格式化标签、SQL标签、XML标签
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:out>
:等同于<%=...>
<c:set>
:用于保存数据<c:remove>
:用于删除数据<c:if>
:与if相同<c:choose>
,<c:when>
,<c:otherwise>
:与switch相同<c:forEach>
:迭代<c:url>
:创造url原文:https://www.cnblogs.com/xiafrog/p/14341830.html