java - 处理 HTTP 状态 500

标签 java jquery ajax exception servlets

在我的 JSP 页面中,我使用以下脚本:

<script type="text/javascript">
$("#birthDate").datepicker({ dateFormat: 'dd/mm/yy' });
$("#update").click(function (e) {
    var res = true;
    var alertMsg = "";
    $(".required").each(function (index) {
        if (this.value == null || this.value.length == 0) {
            alertMsg += this.name + " can't be empty! \n";
            res = false;
        }
    });

    if (res) {
        var response = $("#updateForm").submit();
        Window.location.reload();
    } else {
        alert(alertMsg);
    }
})


但是,请求的资源不可用,并且我收到此异常:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.RuntimeException: org.springframework.remoting.RemoteAccessException: Could not access remote service at [http://some.resource.com]; nested exception is javax.xml.ws.WebServiceException: java.lang.IllegalStateException: Current event not START_ELEMENT or END_ELEMENT
    com.dn.eb.controller.UpdateAccountServlet.throwException(UpdateAccountServlet.java:140)
    com.dn.eb.controller.UpdateAccountServlet.doPost(UpdateAccountServlet.java:122)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

org.springframework.remoting.RemoteAccessException: Could not access remote service at [http://some.resource.com]; nested exception is javax.xml.ws.WebServiceException: java.lang.IllegalStateException: Current event not START_ELEMENT or END_ELEMENT
    org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:510)
    org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:487)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy98.updateAccountRecord(Unknown Source)
    com.dn.eb.controller.UpdateAccountServlet.doPost(UpdateAccountServlet.java:117)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)


如何处理这个异常,以便在我的页面上显示错误消息?

最佳答案

您需要在 web.xml 中声明错误页面:

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

现在应用程序抛出的任何Throwable都将调用error.jsp。或者这样:

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

所有 500 个错误都会调用 error.jsp

error.jsp是一个错误页面,可用于显示错误消息,在error.jsp中声明页面指令:

<%@ page isErrorPage="true"%>

这为您的 JSP 提供了隐式异常对象的句柄。

关于java - 处理 HTTP 状态 500,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17403033/

相关文章:

ruby-on-rails - 如何在页面加载后运行 Twitter gem

ruby-on-rails - 闪光[:notice] not working when using AJAX in Rails

Java 通用堆栈错误

java - Hadoop 2.4 : java. lang.NoClassDefFoundError:org/apache/hcatalog/mapreduce/InputJobInfo

java - Eclipse Java 格式化 : How can I stop wrapping parameters but wrap implements?

javascript - 在 pjax 请求上显示加载文本

javascript - 如何用声音触发特定页面位置的自动页面滚动

jQuery SlideDown 弹回问题

java - 无法读取调制解调器的所有消息

javascript - 通过 jQuery ajax 发送大型 JSON 时出现 404、TypeMismatchError 或 "Not enough storage is available to complete this operation"错误