Page指令和错误页设置

一、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>
错误页面运行效果:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值