1、jsp中的三种注释:
<!-- -->:这个注释在网页中右击查看源代码中可以看见
<%-- --%>:jsp中标准注释
//:java中的注释,用来注释单行
/* * */:多行注释
2、在jsp中键入scriptlet(小脚本程序)的方法有如下几种:
<% %>:用于嵌入代码段
<%! %>:用来声明变量
<%= %>:用来输入表达式
3、jsp中的page指令
作用:page表示当前一个jsp页面,可以理解为一个对象本身,即把一个jsp当做一个对象来看待
功能:设置MIME类型,导包指令,其它指令:错误页面、禁止session、页面缓冲等
4、设置MIME类型:
<%page contentType="text/html;charset=GBK"%>
<%page contentType="application/world;charset=GBK"%>
5、导包指令:import
<%page import="java.sql.*"%> import指令是page指令中唯一可以使用多次的指令
6、包含指令:include
包含指令分为两种:静态包含(@include)和动态包含(jsp:include)
静态包含(@include file=""):可以包含任意格式的文件,只是把文件的内容包含了进来,格式如下:
<%@include file=""%>
动态包含(jsp:include):如果文件包含的是jsp页面,则会先将此jsp页面进行处理后在包含进来,如果是静态页面,则效果是和@include一样的,格式:
<jsp:include page=" " />和
<jsp:include>
<jsp:param name=" 参数" value=" 值" />
</jsp:include>
7、forward指令:跳转指令,当程序遇到此指令时会无条件的跳转,格式如下:
<jsp:forware page=" " />和
<jsp:forware page=" ">
<jsp: param=" name" value=" lhc" /> 可以通过在跳转页面中使用request.getParameter()方法进行接收,接收时注意中文乱码的处理情况
</jsp:forward>
跳转页面实例:forward_first.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>JSP中的跳转指令实例</title>
</head>
<body>
<%--
<jsp:forward page="forward_second.jsp" />不带参数的跳转
--%>
<%
request.setCharacterEncoding("gb2312");
%>
<jsp:forward page="forward_second.jsp">
<jsp:param name="name" value="李海超" />
<jsp:param name="school" value="四川农业大学网络教育学院" />
</jsp:forward>
</body>
</html>
跳转页面:forward_sencond.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%@ page contentType="text/html; charset=gb2312"%>
<html>
<head>
<title>跳转后的页面</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>这是跳转后的页面,跳转前带有参数</h1>
<%
String name = request.getParameter("name");
String school = request.getParameter("school");
%>
<table>
<tr>
<td>姓名:</td>
<td>毕业院校:</td>
</tr>
<tr>
<td><%=name %></td>
<td><%=school %></td>
</tr>
</table>
</body>
</html>