首先是web.xml的jsp配置
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
<trim-directive-whitespaces>true</trim-directive-whitespaces>
</jsp-property-group>
</jsp-config>
其中url-pattern代表控制的那个jsp页面*代表所有
page-encoding代表字码
trim-directive-whitespaces去除内容两边空白
配置错误页面
<error-page>
<error-code>404</error-code>
<location>/indexerr.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/indexerr.jsp</location>
</error-page>
其中的/indexerr.jsp页代码为:
<%@ page language="java" contentType="text/html; charset=UTF-8"
isErrorPage="true"
%>
<!DOCTYPE html>
<html>
<head>
<title>error page</title>
</head>
<body>
<h3>sorry he is not error</h3>
</body>
</html>
isErrorPage=true代表此页面是错误页面(他的默认属性是false)
默认页面index.jsp页面代码:
<%@ page
contentType="text/html; charset=UTF-8"
errorPage="indexerr.jsp"
import="java.util.Date,java.util.List,java.util.ArrayList"
trimDirectiveWhitespaces="true"
%>
<!DOCTYPE html>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
is like<%@ include file="include/date.jsp" %>
</body>
</html>
errorPage代表该页面如果出错显示的错误页面
import导报
trimDirectiveWhitespaces去除内容两边空白
<%@ include file="include/date.jsp" %>引用其他jsp页面
被引用的jsp存放地址

该被引用的jsp页面代码
<%@ page import="java.util.Date,java.text.SimpleDateFormat"%>
<strong>time:<%=new SimpleDateFormat("YYYY-MM-DD HH:mm:ss").format(new Date()) %></strong>
还可以设置IDE工具默认创建的jsp文件的字节码

网友评论