Question

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/

Was it helpful?

Solution 2

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.

OTHER TIPS

Unfortunately not, since (if your ActionForward doesn't redirect) your RequestProcessor will take the URI from the ActionForward and forward it to the RequestDispatcher.

So, you will need to return a null forward after writing data to PrintWriter.

I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top