FileDocCategorySizeDatePackage
ResourceServlet.javaAPI DocExample1751Wed May 14 12:27:12 BST 2003com.jspservletcookbook

ResourceServlet

public class ResourceServlet extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

    
      //get web.xml for display by a servlet
      String file = "/WEB-INF/web.xml";
     
      URL url = null;
      URLConnection urlConn = null;  
      PrintWriter out = null;
      BufferedInputStream buf = null;
     try{
     out = response.getWriter();
     url = getServletContext().getResource(file);
     //set response header
      response.setContentType("text/xml");
    
      urlConn = url.openConnection();
     //establish connection with URL presenting web.xml
     urlConn.connect();
     buf = new BufferedInputStream(urlConn.getInputStream());
     int readBytes = 0;

     //read from the file; write to the PrintWriter
     while((readBytes = buf.read()) != -1)
        out.write(readBytes);

     } catch (MalformedURLException mue){
    
           throw new ServletException(mue.getMessage());
           
     } catch (IOException ioe){
     
        throw new ServletException(ioe.getMessage());
         
     } finally {
     
//close the input/output streams
     if(out != null)
         out.close();
      if(buf != null)
          buf.close();
          }
    
    
public voiddoPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

        
        doGet(request,response);