PDA

View Full Version : Java File Writing Through Backend Package in JSP


obiwanjabroni
08-10-2007, 04:07 PM
So I've been fussing over this tiny code for a while, and although I've gotten some weird kinks resolved (apparently, I need to restart Jakarta Tomcat after every recompile of my Java code), I've come to one error that I cannot seem to resolve. The worst part is that it's hidden.

I'm trying to write a log file since I don't have access to standard out when my web application crashes. So in order for me to see logic errors in the Java, I need to somehow track output. Therefore, I created a Log class that does just that. Unfortunately, I can't see any of my output because it doesn't create it.

The funny thing is, I created a main method in my Log file to test it before I put it as part of the package. And it works beautifully. However, when I make it part of the package and run it through my web app, it doesn't seem to be creating this file.

Any insight would be great!

Oh, and if anyone else could tell me how to run a class that's part of a package from the commandline using javac, that'd be nice too. Thanks in advance!

Here's some relavant code... (NOTE: no syntax errors since it compiles, and I'm competent enough to find extremely obvious ones...if there are syntax errors, that's because I manually typed this out just now since the computer I'm working with that has the code is non-networked)

Login.jsp

<jsp:useBean id="myUser" class="BackEnd.User" scope = "session" />
<%
myUser.do_initialize(request.getParameter("username"));
%>


BackEnd.User

//...in class definition...
public void do_initialize(String p_user)
{
// ...
Log.do_log("Initializing");
// ...
}


BackEnd.Log

//...in class definition...
public static void do_log(String p_toLog)
{
try
{
File myOutfile = new File("backend.log");
boolean attempt = myOutfile.createNewFile();
PrintWriter myOutstream = new PrintWriter(new OutputStreamWriter(new FileOutputStream(myOutfile, true)));
myOutstream.println(new Date());
myOutstream.println(p_tolog);
myOutstream.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}

obiwanjabroni
08-10-2007, 04:15 PM
I'm sorry, the problem seems to have resolved itself. I had to restart the entire computer for it to start compiling the JSP correctly?

Once again, sorry could an admin please delete this thread?