JSP 指令和动作

errorParoge 和isErrorPage指令

errorpage:指定发生异常时错误页面显示的内容。errorPage="/error.jsp"
isErrorPage:可以设置错误页面报的错误。默认情况下值为false,设置为true时,可以显示错误信息。isErrorPage="true"

<body>
    error.jsp
    ex=<%=exception.getMessage()%>
</body>

session指令

使用request的 getSession()原则:
若向session中存放数据时,则使用getSession(true),即创建一个Session
若向session中读取数据时,则使用getSession(false),即使用原先的Session

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" session="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
		<%
		HttpSession session = request.getSession(false); 
		if(session != null){
			String user = (String)session.getAttribute("user");
			out.print(user);
		}
		
		%>
</body>
</html>

include 指令

1.静态联编
项目运行时,会创建一个java和class文件。
include:包含一个页面,在编译前就将包含的页面的代码添加到被包含页面中。共用一个servlet。

<%@ include file="/next.jsp" %>

forward动作和include动作

对应着servlet中请求转发的forward和include,标准输出流的开启不同。

		<jsp:forward page="/hello.jsp"></jsp:forward>
		<jsp:include page="/hello.jsp"></jsp:include>

include指令和include动作的区别,项目运行时,会创建各自的java和class文件。存在不同的servlet,各种互不影响。

发布了114 篇原创文章 · 获赞 8 · 访问量 5484

猜你喜欢

转载自blog.csdn.net/OVO_LQ_Start/article/details/104781357
今日推荐