<%@ page import="java.io.*"%>
包含指令,页指令,taglib指令
包含在<%@ %>卷标里
两个主要的指令page include
<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%> <%@ include file=""%>
<jsp:forward page=""> <jsp:param name="username" value="arthinking" /> </jsp:forward>
参数可以从另外一个页面的getParameter方法获取。
在指令后的所有代码都不会执行,而直接跳转到另外一个页面进行执行。
<jsp:forward>实际上是调用了PageContext的forward方法。
<jsp:include page=""> <jsp:param name="username" value="arthinking" /> </jsp:include>
参数可以从另外一个页面的getParameter方法获取。
request的getRequestDispatcher和getRequestDispatcher的forward方法说明:
请求转发,保存了ServletRequest中setAttribute的参数,可以使用这种方法传递参数:
req.setAttribute("username", "arthinking"); RequestDispatcher rd = req.getRequestDispatcher("message.jsp"); rd.forward(req, resp);
在同一个请求里面,可以使用getParameter方法获取setAttribute方法设置的参数。
getRequestDispatcher public RequestDispatcher getRequestDispatcher(String path)
The default behavior of this method is to return getRequestDispatcher(String path) on the wrapped request object.
Specified by: getRequestDispatcher in interface ServletRequest
Parameters: path - a String specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns: a RequestDispatcher object that acts as a wrapper for the resource at the specified path, or null if the servlet container cannot return a RequestDispatcher
See Also: RequestDispatcher, ServletContext.getRequestDispatcher(java.lang.String)
HTML注释:<!-- -->
隐藏注释:<%-- --%> 不发送到客户端
<%=new java.util.Date() %>
等号开头,不用分号作为结尾。
<%! int a = 1; %>
声明和脚本段转换为Servlet代码的位置是不一样的,声明语句定义的变量会方法成员变量的位置,而脚本段中的变量会转换为局部变量。每个用户都会访问到成员变量,而脚本段的局部变量每个用户保存一个副本,互不影响。声明语句的变量在重新刷新页面时不会被重新定义,所以在_jspService方法中修改的状态是会保留下来的。
对于Servlet来说,是单例模式的。
但是这种声明语句用的比较少,因为这种需求不是很多。