一、Page指令
交互处理表格的显示(PrintTable.jsp)<html>
<head>
<title>ZhangZe交互处理表格的显示</title>
</head>
<body>
<table border = "1" width = "80%">
<%
int rows = 0;
int cols = 0;
try{ // 接收数据为Int型
rows = Integer.parseInt(request.getParameter("rows"));
cols = Integer.parseInt(request.getParameter("cols"));
}catch (Exception e){
}
for (int i = 0; i < rows; i++){
%>
<tr>
<%
for (int j = 0; j < cols; j++){
%>
<td bgcolor="#CCCCCC"><%= (i*j)%></td>
<%
}
%>
</tr>
<%
}
%>
</table>
</body>
</html>
交互处理表格的显示(PrintTable.htm)
<html>
<head>
<title>ZhangZe交互处理表格的显示</title>
</head>
<body>
<form action = "PrintTable.jsp" method = "post">
<table border = "1" width = "80%">
<tr>
<td>请输入显示表格的行数:</td>
<td><input type="text" name = "rows"></td>
</tr>
<tr>
<td>请输入显示表格的列数:</td>
<td><input type = "text" name = "cols"></td>
<tr>
<tr>
<td colplan = "2"><input type = "submit" value = "显示"></td>
<td><input type = "reset" value = "重置"></td>
</tr>
</table>
</form>
</body>
</html>
运行效果:
二、设置页面的EIME
在Tomcat 5.5安装目录\conf的web.xml文件中查看关于EIEM的映射.
eg:希望页面按Word文档显示,可以使用以下EIME类型
<mime-mapping>
<extension>doc</extension>
<mime-type>application/msword</mime-type>
</mime-mapping>
为页面指定MIME编码-word显示
<%@ page language = "java"contentType = "application/msword; charset = GBK"%>// 容易出错的地方
<html>
<head>
<title>为页面指定MIME编码-word显示</title>
</head>
<body>
<tableborder = "1">
<%//指定文件下载保存的文件名为:zz.doc
response.setHeader("Content-Disposition","attachment ;filename = zz.doc");
%>
<tr><td>欢迎大家来到程序猿的空间</td></tr>
<tr><td>网址:http://my.csdn.net/zhangze_wancheng</td></tr>
<tr><td>本网页将使用Word显示</td></tr>
</table>
</body>
</html>
页面运行效果:
打开文档效果:
三、错误页的设置
会出现错误的页面及设置:show.jsp
<%@ page language = "java" contentType = "text/html" pageEncoding = "GBK"%>
<%@ page errorPage = "error.jsp"%> <%--一旦出现错误之后将跳转到error.jsp中--%>
<%
int result = 10 / 0; // 操作错误
%>
<h1>欢迎进入本页面!</h1>
将处理错误的页面:error.jsp
<%@ page language = "java" contentType = "text/html" pageEncoding = "GBK"%>
<%@ page isErrorPage = "true"%> <%--表示此页面可以处理错误!--%>
<%
response.setStatus(200); <%--防止出现无法跳转的出错页--%>
%>
<h1>本页面发现:程序出现错误!</h1>
错误页面运行效果: