JSP基础语法(二)——page 指令常用属性

1.autoFlush     = "true/false"

2.buffer           >= 8KB

3.contentType  = "text/html;charset=GBK"

4.errorPage      = "error.jsp"

5.isErrorPage    = "true/fase"

6.extends         = "父类名称"

7.import           ="包名"

8.info               = "text info"

9.language        ="java"

10.pageEncoding ="GBK"(中文)

11.session        ="true/fase"

12.isThreadSafe  = "true/fase"

 

设置MIME类型,如设置为doc,那么打开网页时就会提示使用doc打开。可以给doc自己命名

<%@ page language="java" import="java.util.*"
contentType
="application/msword;charset=GBK"%>



<%
response.setHeader(
"Content-Disposition", "attachment;filename=lihui.doc");
%>

 

使用contentType和pageEncoding设置编码的区别:

pageEncoding指的是JSP文件本身的编码,而contentType中的charset指的是服务器发送给客户端的内容编码。

 

对错误页的处理可以在每一个JSP页面中设置,也可以设置一个全局的错误页,程序运行错误后都跳到同一个错误页,这需要在工程的web.xml中设置

 <error-page>
<error-code>404</error-code>
<location>index.jsp</location>
</error-page>
<error-page>
<exception-type>java.long.NullPointerException</exception-type>
<location>index.jsp</location>
</error-page>

这样,错误页都会跳转至index.jsp上

posted @ 2011-10-09 15:10  lihui_yy  阅读(288)  评论(0编辑  收藏  举报