
Web Services and AJAX • 443
case 2: sandwiches [0] = “veg”;
sandwiches [1] = “jam”;
sandwiches [2] = “cheese”;
break;
}
response.setContentType(“text/xml”);
out.println (“<?xml version=\”1.0\”?>”);
out.println (“<sandwiches>”);
for (int i=0; i<3; i++) {
out.println (“<sandwich>”);
out.println (sandwiches [i]);
out.println (“</sandwich>”);
}
out.println (“</sandwiches>”);
%>
Figure 9.37 JSP page to generate XML dynamically at run time
Understanding this JSP should be simple. We first read the value of a parameter named type, which the
caller is expected to send to our JSP. It then creates an empty string array of three subscripts. ...