[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Temporary Files and Servlets or JSP

Posted on 2004-10-21
11
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What monsters are hiding in your child's room? In this article I will share with you a tech horror story that could happen to anyone, along with some tips on how you can prevent it from happening to you.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

649 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