Sunday 15 February 2015

java - Struts 2 - Interceptor reset the response JSON Object -


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

No comments:

Post a Comment