Hi all,
I have a
servlet where i am forming this xml
string and passing it back to the
JSP.
The servlet code:
package wwxchange;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import wwxchange.utility.*;
import wwxchange.beans.*;
public class AutoComplete extends HttpServlet {
private ServletContext context;
//Initialize global variables
public void init(ServletConfig config) throws ServletException {
this.context = config.getServletContext();
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String searchBy = request.getParameter("searchBy");
String id = request.getParameter("id");
String action = request.getParameter("action");
boolean added = false;
ArrayList list = new ArrayList();
StringBuffer sb = new StringBuffer();
HttpSession session = request.getSession();
UserAcctBean user = (UserAcctBean) session.getAttribute("currentuser");
AirbillBean ab = (AirbillBean) session.getAttribute("currentshipment");
String loginID = user.getLoginID();
String accountNbr = user.getAcctNum();
if(id != null)
id = id.trim().toLowerCase();
list = ab.getNamesForAutoComplete(id, accountNbr, searchBy);
for(int i=0;i<list.size();i++) {
sb.append("<customer>");
sb.append("<companyName>" + list.get(i) + "</companyName>");
sb.append("</customer>");
added = true;
}
if(added) {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write("<search>" + sb.toString() + "</search>");
} else {
//nothing to show
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
context.getRequestDispatcher("/CreateShipment.jsp").forward(request, response);
}
//Clean up resources
public void destroy() {
}
}
When I access this response from the JSP, it is adding the JSP code from the CreateShipment.jsp page to ehich i am forwarding the respose to in the response body along with the xml string.
I cant commit the response in the servlet coz i am writing to the writer. That gives me an
IllegalStateException. What is it that i am missing here?
Thanks in advance.
harmeet
[ January 07, 2007: Message edited by: Bear Bibeault ]