FileDocCategorySizeDatePackage
AjaxResponseServlet.javaAPI DocExample2437Sun Apr 30 10:09:04 BST 2006com.oreilly.ajax.servlet

AjaxResponseServlet

public class AjaxResponseServlet extends HttpServlet

Fields Summary
private static final long
serialVersionUID
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)


	     
               
        // key is the parameter passed in from the javascript
        // variable named url (see index.html)
        String key = req.getParameter("key");
        StringBuffer returnXML = null; 
        if (key != null) {

            // extract the first character from key
            // as an int, then convert that int to a String
            int keyInt = key.charAt(0);
            
            returnXML = new StringBuffer("\r\n<converted-values>");
            returnXML.append("\r\n<decimal>"+
                                Integer.toString(keyInt)+"</decimal>");
            returnXML.append("\r\n<hexadecimal>0x"+
                                Integer.toString(keyInt,16)+"</hexadecimal>");
            returnXML.append("\r\n<octal>0"+
                                Integer.toString(keyInt,8)+"</octal>");
            returnXML.append("\r\n<hyper>&0x"+
                                Integer.toString(keyInt,16)+";</hyper>");
            returnXML.append("\r\n<binary>"+
                                Integer.toString(keyInt,2)+"B</binary>");
            returnXML.append("\r\n</converted-values>");
            
            // setup the response
            res.setContentType("text/xml");
            res.setHeader("Cache-Control", "no-cache");
            // write out the xml string
            res.getWriter().write(returnXML.toString());
        }
        else {
            // If key comes back as a null, return a question mark.
            res.setContentType("text/xml");
            res.setHeader("Cache-Control", "no-cache");
            res.getWriter().write("?");
        }