1 22 package org.jboss.test.securitymgr.servlet; 23 24 import java.io.IOException ; 25 import java.io.File ; 26 import javax.servlet.http.HttpServlet ; 27 import javax.servlet.http.HttpServletRequest ; 28 import javax.servlet.http.HttpServletResponse ; 29 import javax.servlet.ServletException ; 30 31 37 public class FileAccessServlet extends HttpServlet 38 { 39 protected void doGet(HttpServletRequest req, HttpServletResponse resp) 40 throws ServletException , IOException 41 { 42 try 43 { 44 resp.addHeader("X-CodeSource", ""+getClass().getProtectionDomain().getCodeSource()); 45 String fileName = req.getParameter("file"); 46 String root = super.getServletContext().getRealPath("/"); 47 resp.addHeader("X-RealPath", root); 48 File file = new File (root, fileName); 49 boolean exists = file.exists(); 51 boolean created = false; 52 boolean deleted = false; 53 if( exists == false ) 54 created = file.createNewFile(); 55 else 56 deleted = file.delete(); 57 resp.addHeader("X-Exists", ""+exists); 58 resp.addHeader("X-Created", ""+created); 59 resp.addHeader("X-Deleted", ""+deleted); 60 } 61 catch(Exception e) 62 { 63 resp.addHeader("X-Exception", ""+e.getMessage()); 64 resp.addHeader("X-ExceptionClass", e.getClass().getName()); 65 } 66 } 67 } 68 | Popular Tags |