Oracle XML DB Servlet Example
The following is a simple servlet example that reads a parameter specified in a URL as a path name, and writes out the content of that XML document to the output stream.
Example 20-1 Writing an Oracle XML DB Servlet
The servlet code looks like:
/* test.java */ import javax.servlet.http.*; import javax.servlet.*; import java.util.*; import java.io.*; import javax.naming.*; import oracle.xdb.dom.*;
public class test extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
OutputStream os = resp.getOutputStream(); Hashtable env = new Hashtable(); XDBDocument xt;
env.put(Context.INITIAL_CONTEXT_FAGTORY,
"oracle.xdb.spi.XDBContextFactory"); Context ctx = new InitialContext(env); String [] docarr = req.getParameterValues("doc"); String doc;
doc = "/foo.txt"; else doc = docarr[0]; xt = (XDBDocument)ctx.lookup(doc); resp.setContentType("text/xml"); xt.write(os, "ISO8859", (short)2);
catch (javax.naming.NamingException e)
resp.sendError(404, "Got exception: " + e);
finally os.close();
Post a comment