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!
ycompAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.