<% // 运行错误 int result = 10 / 0; %>
设置如果出现错误,跳转到error.jsp文件
错误页的跳转属于服务器端跳转
maven安装驱动
访问网址
https://search.maven.org/artifact/mysql/mysql-connector-java/8.0.15/jar
输入依赖
<dependency> <groupid> mysql </groupid> <artifactid> mysql-connector-java </artifactid> <version> 8.0.15 </version> </dependency>
<%@ page import="java.sql.*" %>
网页分为头尾中
在jsp编译的时候插入一个包含文本或代码的文件。包含过程为静态的,代码文件包含,生成一个完整的jsp文件,再次包含生成class文件,加载进入容器。
<%@include file="info.html"%><%@include file="info.inc"%>
<%-- Created by IntelliJ IDEA. User: ming Date: 19-3-9 Time: 下午3:43 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> 参数1<%=request.getParameter("name")%> 参数2<%=request.getParameter("info")%>
<%-- Created by IntelliJ IDEA. User: ming Date: 19-3-9 Time: 下午4:51 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
运行以后可以发现显示出结果
两种包含,静态包含是先包含,后处理,动态包含为先处理后包含
此跳转为服务端跳转
即一个request传递到另外一个page
<%-- Created by IntelliJ IDEA. User: ming Date: 19-3-9 Time: 下午5:14 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%-- Created by IntelliJ IDEA. User: ming Date: 19-3-9 Time: 下午5:11 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <% String username = "LiHua"; %> <jsp:forward page="forward_demo02.jsp"> <jsp:param name="name" value="<%=username%>" /> <jsp:param name="info" value="ming" /> </jsp:forward>
未分类