1

I am making ajax calls from my JS methods to invoke the action class's methods in the following manner:

$.getJSON("treeDemo_!getRootNode?appId=" + applicationId, function () {
    }).success(function (e) {
    }).error(function (jqXHR, textStatus, errorThrown) {
        alert(textStatus);
    }).complete(function () {
    });

Session configuration in my web.xml looks like this

<session-config>
    <session-timeout>1</session-timeout>
</session-config>

Now when the session expires after 1 minute, the ajax call returns error (without calling the action method). The error says

textStatus = parsererror
errorThrown = SyntaxError: JSON.parse: unexpected character

But this looks like a generic error. I want to catch the session timeout exception and redirect the user to the login.jsp page in case this exception occurs.

I even tried handling it by doing this. But it didn't work for me.

Can you please suggest how should I solve it?

4

1 回答 1

1

没有“会话超时异常”。

您的 Ajax 调用期望返回 JSON,如果会话超时,您的应用程序中没有任何内容会返回 JSON。在链接中使用过滤器或拦截器,检查会话超时,如果是正常请求则正常处理,但如果是 Ajax 请求,则返回 HTTP 错误代码。

在您的 JavaScript 回调中处理此错误代码。

于 2013-02-05T13:34:28.407 回答