Search code examples
javaajaxstrutsstruts1

Ajax and Struts 1.x Integration without PrintWriter


Is it possible to write Struts Action class to render the part of the page with help of ajax without PrintWriter? I've heard that it's possible to do forward to the part of the page. For example it's solution with PrintWriter: http://www.raistudies.com/struts-1/ajax-with-struts-example/


Solution

  • It depends on what your AJAX request expects in answer.

    • if it expects JSON/XML/other non-HTML stuff, then you should use PrintWriter to write that stuff to HTTP response.

    • if it expects HTML content (inserts received content into your page), then you could forward from your action to JSP file, which will contain just the HTML fragment you want to return.