日期:2014-05-18  浏览次数:20609 次

如何让浏览器显示我自定义的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)这样