2013-07-01 191 views
0

在我的JSP頁面中我使用這個腳本: 處理HTTP狀態500

<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) 


如何處理此異常,以便在我的頁面上顯示錯誤消息?

+0

你想顯示一些錯誤頁面與用戶友好的文字,而不是此異常? – sanbhat

+1

如果你想顯示自定義錯誤頁面,這將對你有用:[如何在web.xml中指定默認錯誤頁面?](http://stackoverflow.com/questions/7066192/sp​​ecify-the-default-錯誤頁面中的Web-XML的在小服務程序) – informatik01

回答

1

你需要在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的句柄隱含exception目的。

0

您應該看到來自您的遠程方的實際響應。很可能你會看到一些樣板文件HTML,說你的資源沒有找到,你沒有授權,或類似的東西,而不是實際的WS響應。當WS服務器隱藏在Apache前端後面時會發生這種情況,該前端被錯誤配置爲假定您是瀏覽器。

相關問題