首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

怎么让浏览器显示我自定义的404错误页面

2011-12-22 
如何让浏览器显示我自定义的404错误页面?自己写了个http服务器想要自定义个404错误页面希望在浏览器上显示

如何让浏览器显示我自定义的404错误页面?
自己写了个http服务器
想要自定义个404错误页面
希望在浏览器上显示     File   Not   Found
但是浏览器只会使用默认的那个404错误页面
而不用我的
请教如何让我的页面优先于浏览器的页面显示
该在文件头里加点什么?

代码如下
String   errorMessage   =   "HTTP/1.0   404   File   Not   Found\r\n "   +   "Server:   java\r\n "   +   "Content-Type:   text/html\r\n "   +   "\r\n "   +   " <h1> File   Not   Found </h1> ";
output.write(errorMessage.getBytes());

[解决办法]
web.xml

...
<error-page>
<exception-code> 500 </exception-code>
<location> /error.jsp </location>
</error-page>
...
[解决办法]
或者在jsp里面加上 <@page errorpage= "error.jsp " iserrorpage= "true ">
[解决办法]
IE 的Internet 选项中有一项是 显示友好的http错误信息 你把这个关了 看看是不是你想要的结果 随便说下 自己写http服务器 多累呀
[解决办法]
你用out.print是没有意义的,因为只是你的文本含有404,实际上http头中还是返回了表明正确的200代码

你应该使用response.sendError(404)这样

热点排行