JSP and Ajax

Hi,

Is it a good idea, or even possible to dispatch JSP pages from a servlet back to an XmlHttpRequest object, or should we send the information through a writer obtained in the servlet like most examples I have seen?

I want to forward (or actually return an ActionMapping, since I am using Struts) from the servlet to a JSP page like the following:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<select id="selectCompany" size="15">

<c:forEach var="item" items="${companyList}">

<option value="${item.id}">${item.name}</option>

</c:forEach>

</select>

And have this arrive back at the client, and attached via Javascript directly to a div or span on the originating page.

Are there any sources/examples I could reference to better see how to do this? All of the examples I have seen send the information from inside the servlet, and this is very messy.

[1208 byte] By [bear-98765a] at [2007-11-26 21:10:54]
# 1

If i didn't misunderstood, it'll be ok to set the action mapping to the JSP, call the .do from the XmlHttpRequest and assign the result to a div.innerHTML

I'm not too deeply involved in struts, but in a servlet it would be like

request.getRequestDispatcher("theJsp.jsp").forward(request, response);

The JSP you already posted and on the XmlHttpRequest handler

theTargetDiv.innerHTMl = req.responseXML;

benubacha at 2007-7-10 2:48:02 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...