Last active
August 29, 2015 14:10
-
-
Save rafayali/0da3ea48acb2f5a7e6dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Sends data back to client by using HTTPServletResponse object and adding data into JSON Array | |
* then flushes out the stream and closes the response | |
* Sends data | |
* @param resp | |
* @param result | |
* @param message | |
* @param stringData | |
* @throws IOException | |
*/ | |
public static void sendData(HttpServletResponse resp, String result, String message, List<String> stringData) throws IOException { | |
JSONArray data = new JSONArray(); | |
data.put(result); | |
data.put(message); | |
if(stringData != null) | |
for(String s : stringData){ | |
data.put(s); | |
} | |
final String output = data.toString(); | |
resp.setContentLength(output.length()); | |
resp.getOutputStream().write(output.getBytes()); | |
resp.getOutputStream().flush(); | |
resp.getOutputStream().close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment