繁体   English   中英

处理HTTP状态500

[英]Handle HTTP status 500

在我的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指令:

<%@ page isErrorPage="true"%>

这使您的JSP可以处理隐式exception对象。

您应该从远端看到实际的响应。 很可能您会看到一些样板HTML内容,说明找不到资源,未授权或类似的内容,而不是实际的WS响应。 当WS服务器隐藏在Apache前端的后面时,可能会发生这种情况,这是错误地配置为假定您是浏览器。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM