----------------------------------------------------------------
BEFORE YOU POST, search the faq at <http://java.apache.org/faq/>
WHEN YOU POST, include all relevant version numbers, log files,
and configuration files.  Don't make us guess your problem!!!
----------------------------------------------------------------

> > Subject: security manager
> >
> > Hi all,
> >
> > I intend to rename files using servlets with no success. I think it's
> > related to security issues since the standaloneJava
> > application can do the
> > job.  Can anyone tell me how to configure Apache JServ to
> > allow such access?
> > Or is it possible.
>
> Servlets may do everything like a standalone Java Application. They're
> running on the server and are programmed by people who are supposed to
know
> what they do (ha ha).

What you said is absolutely NOT true. Have you ever read any book on servlet
programming? There are restrictions. By the way I do know how to program.

> Give your error messages or example code so we can see what's going wrong.

There is NO error message. I even tried using external commands from Java.
Only "ls or finger" works

Here is the code for the servlet which does not work.

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class testRename extends HttpServlet
{
 public void init(ServletConfig config) throws ServletException
 {
  super.init(config);
 }//end init

 public void doPost( HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException
 {
  doGet(req, res);
 }

 public void doGet( HttpServletRequest req, HttpServletResponse res)
  throws ServletException, IOException
 {
  PrintWriter out = res.getWriter();
  res.setContentType("text/html");
  File file1 = new File("/projects/lemonade/test","temp1.html");
  File file2 = new File("/projects/lemonade/test","TEMP1.html");
  if (file1.renameTo(file2))
   out.println ("succeeded");
  else
   out.println ("failed");
  out.close ();
 } // doGet

} // end of calss testRename


Here is the code for Standalone application, which works.
import java.io.File;

class Mv {
    public static void main(String[] args) {
        if (args.length != 2) {
            System.err.println("Usage: java Mv <file1> <file2>");
            System.exit(-1);
        }
        File f1 = new File(args[0]);
        File f2 = new File(args[1]);

        if (f1.equals(f2)) {
            System.err.println("Cannot rename a file to itself");
            System.exit(-1);
        }
        System.out.println(f1.getPath() +
           (f1.renameTo(f2) ? " renamed to " : " could not be renamed to ")
+
                           f2.getPath());

        // check f1 and f2: their path and hash codes remain unchanged
        System.out.println("f1: " + f1.toString() + " " + f1.hashCode());
        System.out.println("f2: " + f2.toString() + " " + f2.hashCode());
    }
}






--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to