struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Grobmeier <grobme...@gmail.com>
Subject Re: Returning response object only from Action
Date Wed, 28 Sep 2011 14:41:33 GMT
Hi Ajib,

> public ActionForward execute(ActionMapping mapping, ActionForm inForm,
> HttpServletRequest request, HttpServletResponse response) throws Exception {
>
>        // Get a list of characters associated with the select TV show
>        String tvShow = (String) request.getParameter("tvShow");
>        if (tvShow == null) {
>            tvShow = "";
>        }
>

// use a json lib, like: http://code.google.com/p/jjson/
// to generate json from an arrayList

List<String> character = getCharacters(tvShow);
    		JSONArray arr = new JSONArray();
    		for (String string : character) {
    			arr.add(new JSONString(string));
			}
    		
    		String responseString = arr.toJSON();

// use text/plain:
>        response.setContentType("text/plain");
>        PrintWriter out = response.getWriter();

// use response String
>        out.println(responseString);
>        out.flush();
>
>        return null; // Not forwarding to anywhere, response is fully-cooked
>
>    } // End execute()
>
> How can I avoid creating HTML in action class and send the Arraylist /JSON
> to view?

Similar to that. :-)

Cheers
Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message