Hi All,

I want to know how I can send the repose object with JSON content to the view from the Action class.

I am trying to add AJAX feature in Struts 1.3.8 application as shown in http://www.zammetti.com/articles/xhrstruts/index.htm.

Instead of doing

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 = "";
        }
        ArrayList characters = getCharacters(tvShow);

        // creating HTML in an Action
        String html = "<select name=\"CharactersSelect\">";
        int i = 0;
        for (Iterator it = characters.iterator(); it.hasNext();) {
            String name = (String) it.next();
            i++;
            html += "<option value=\"" + i + "\">" + name + "</option>";
        }
        html += "</select>";

        // Write the HTML to response
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        out.println(html);
        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?

Thanks,
Anjib



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

Reply via email to