Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 299
  • Last Modified:

Temporary Files and Servlets or JSP

Hi,

I am writing a class that will be used from within a JSP or Servlet.

If an exception occurs then I want to be able to create a temporary file and output detailed info to there. I want to create a temporary html file for this. The reason for this is there is a lot of "rich" content that cannot be described as text in an exception message.

In the exception message I would tell the user to look at this file.

I would like to know:

1) Can temporary files be reliably created somehow? Or will there be permissions problems sometimes?

2) will these files be deleted themselves eventually or am I responsible for that?

thanks!
0
ycomp
Asked:
ycomp
  • 4
  • 3
  • 2
  • +1
1 Solution
 
kiranhkCommented:
1) you can create temporary files on the Server. there will not be any security problems while creating the files on the server side
2) no, you need to take care of deleting the files

this thread might be of some help

http://archives.java.sun.com/cgi-bin/wa?A2=ind9901&L=servlet-interest&F=&S=&P=105914
0
 
ycompAuthor Commented:
thanks for the quick answer!

I don't really want to add the overhead of deleting files so now I'm thinking just to use the same name every time.

e.g. "debugdump.html" and have it created in the default temporary directory.

How do I do that? just new File("debugdump.html") ? would that put it in the temp dir or in the current dir? What about new FileWriter("debugdump.html")?
0
 
petmagdyCommented:

U need to lock into Log4J get it from jakarta.apache.com
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kiranhkCommented:
i have not used that,
u can also check out the JDK logging api or as petmagdy suggested the Log4J

http://javaalmanac.com/egs/java.util.logging/pkg.html
0
 
ycompAuthor Commented:
I see... but I need to create a richly formatted HTML document. it is not logging really. It is an illustration of what went wrong that led to this particular exception.
0
 
kiranhkCommented:
then better go in for file writing, u can get lots of example code for the same from the above link which i gave u
0
 
petmagdyCommented:
take a more look log4j supports multiple formats
0
 
ycompAuthor Commented:
ok, thanks.

does anyone have an answer to this though?

-------
I don't really want to add the overhead of deleting files so now I'm thinking just to use the same name every time.

e.g. "debugdump.html" and have it created in the default temporary directory.

How do I do that? just new File("debugdump.html") ? would that put it in the temp dir or in the current dir? What about new FileWriter("debugdump.html")?
---------
0
 
siliconeagleCommented:
something like this:-
static String path="D:\\log";
      public void  fileDumpEx(Exception e) {
            try {
                  FileWriter f=new FileWriter(path+File.separator+"debugdump.html");
                  f.write("<html><body>");
                  f.write(e.getClass().getName()+" - " +e.getMessage()+"<br/>");
                  StackTraceElement[] stack=e.getStackTrace();
                  for (int i=0;i<stack.length;i++) {
                        f.write(stack[i].getLineNumber());
                        f.write(":");
                        f.write(stack[i].getClassName());
                        f.write("#");
                        f.write(stack[i].getMethodName());
                        f.write("<br/>\n");
                  }
//                  this just dumps in the stacktrace as text.
//                  f.write("output of stacktrace.");
//                  PrintWriter pw=new PrintWriter(f);
//                  e.printStackTrace(pw);
//                  
                  f.write("</body></html>");
                  f.close();
            } catch (IOException e1) {
                  
            }
            finally {
                  
            }
            
            
      }
      public void method() {
            String h=null;
            try {
                  h.toString();
            }
            catch (Exception e) {
                  fileDumpEx( e);
                  
            }
      }
0
 
siliconeagleCommented:
did this help? havent heard any more on this thread.
0
 
ycompAuthor Commented:
sorry I got caught up on other things. I'll get back to this eventually and accept an answer. thanks for your help.
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now