I am using String 2 in my web application. I write the code to check the user session in the interceptor, but when I return the code as net.sf.json.JSONObject , reset its reset object and empty set for the object Please. Please check my code.
Import net.sf.json.JSONObject; Import com.opensymphony.xwork2.interceptor.Interceptor; Public class authority interceptor interceptor applied {JSONObject feedback = new JSONObject (); Public string interruption {try {map session = invocation.getInvocationContext} GetSession (); If (session.get ("userId") == tap) {response.put ("errorCode", "SESSION_OUT"); Withdrawal support.ERROR; } And {System.out.println ("found the session"); Object Action = Involvement. Gate action (); Return invocation.invoke (); }} Hold (exception e) {return ActionSupport.ERROR; }} Public JSONObject getResponse () {Return response; } Public Zero Set Response (JasonOnbise Response) {this.response = response; }
}
How do I get JSON objects as feedback from interceptor? Please help me solve this problem.
Your code has multiplyable errors.
- The response is, you should not give a JSONObject to that name.
- Interceptor is not THREAD-SAFE, it means that you should define JSONObject within the method to prevent multiple users from updating. This concurrently, on each other < Li> You should use the status code or error code, which you can configure as returning error result:
Use the status code to set Response status:
& lt; Name of the result = "error" type = "json" & gt; & Lt; Param name = "status code" & gt; 304 & lt; / Param & gt; & Lt; / Results & gt; and the error code to send an error (the server client may have some sender end that is not the serialized JSON):
& lt; Name of the result = "error" type = "Jason" & gt; & Lt; Param name = "errorCode" & gt; 404 & lt; / Param & gt; & Lt; / Results & gt; And then read client-side in the AJAX callback function.
No comments:
Post a Comment