Improve company productivity with a Business Account.Sign Up

x
?
Solved

Temporary Files and Servlets or JSP

Posted on 2004-10-21
11
Medium Priority
?
301 Views
Last Modified: 2010-04-01
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
Comment
Question by:ycomp
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 8

Expert Comment

by:kiranhk
ID: 12375110
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
 

Author Comment

by:ycomp
ID: 12375219
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12375241

U need to lock into Log4J get it from jakarta.apache.com
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LVL 8

Expert Comment

by:kiranhk
ID: 12375309
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
 

Author Comment

by:ycomp
ID: 12375348
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
 
LVL 8

Expert Comment

by:kiranhk
ID: 12375375
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
 
LVL 13

Expert Comment

by:petmagdy
ID: 12375383
take a more look log4j supports multiple formats
0
 

Author Comment

by:ycomp
ID: 12375454
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
 
LVL 2

Accepted Solution

by:
siliconeagle earned 2000 total points
ID: 12401888
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
 
LVL 2

Expert Comment

by:siliconeagle
ID: 12481666
did this help? havent heard any more on this thread.
0
 

Author Comment

by:ycomp
ID: 12484470
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

As a Tester when requirement in software testing changes consistently every team member should be prepared to deal with the adjustments in the project.
You can use the network upload option and the Office 365 Import service to bulk-import PST files to user mailboxes. Network upload means that you upload the PST files a temporary storage area in the Microsoft cloud.
Watch the video to know how one can repair corrupt Exchange OST file effortlessly and convert OST emails to MS Outlook PST file format by using Kernel for OST to PST converter tool. It can convert OST to MSG, MBOX, EML to access them. It can migrate…
Watch the video to know the process of migration of Exchange or Office 365 mailboxes in absence of MS Outlook. It is an eminent tool which can easily migrate Public, Archive user mailboxes from one another Exchange server and Office 365. Kernel Migr…

584 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question