Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
247 views
in Technique[技术] by (71.8m points)

java - Custom Error Page in Tomcat 7 for Error Code 500

Guys I am struggling with the problem of opening my custom error page in Tomcat in Windows Environment. Some of solution I got but no luck. I tried almost all links but its not working for me. Some of them working for other solution deployed in Tomcat but not for my Web Service

My web.xml

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
    <location>/error.html</location>
</error-page>


I am sending error from my Servlet 3.0 Application response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);

I have put my error.html in the root directory of my WebService.

Some of the links I got for JSP page instead of HTML that also I have tried

In case of JSP I used:

<%@ page isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
</head>
<body>
    <h1>Error</h1>
</body>
</html>


FYI it is working fine for other Tomcat inbuilt solution it's working perfectly. But in my Webservice I am getting response 500 but page is opening blank. And one other thing I have disabled my Internet Explorer 9.0 show error friendly page still response coming 500 from servlet. But error page is coming empty.

If any idea or any doubt about my query just let me know. I need it ASAP.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try putting the following snippet in your WEB-INF/web.xml

<error-page>
    <error-code>500</error-code>
    <location>/Error.jsp</location>
</error-page>

<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/Error.jsp</location>
</error-page>

In this case Error.jsp is at the same level as WEB-INF directory (not inside it).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...