Problem creating text files with JSP

M

miguelcampoy

Hi everybody!

Im developing a web application with JSP, and im finding this problem.
Im trying to create a text file with some information. This is an
extraction of the code im using:

....

import java.io.BufferedWriter;
import java.io_OutputStreamWriter;
import java.io.FileOutputStream;

....

public void toLogFile(String fileNameIn, String comentarioIn){
String path = "";
try{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(path + fileNameIn, true)));
String resultado = "";
bw.write("PEDIDO: ");
bw.newLine();
bw.write("Cliente: " + getClientName());
bw.newLine();

// code for finding what i want to write in the text file

if (suReferencia != "") resultado += "Referencia de cliente: " +
suReferencia + "\n";
resultado += "Comentarios: " +
Conversor.procesaComentario(comentarioIn) + "\n";
for(int i = 0; i < numDetalles; i++){
resultado += " - " + detalles.detalleToString() + "\n";
}
// Found what i want to write. Now i write it in the text file.

bw.write(resultado);
bw.newLine();
bw.flush();
bw.close();
}
catch(Exception e){
System.err.println("---Logger Exception---");
System.err.println("Mensaje: " + e);
}
}

This works fine in my development computer, whose operating system is
Windows XP, but when i try it in my production computer, with UNIX
instead of Windows, the JSP that calls the method "toLogFile" returns
this error (in spanish):

org.apache.jasper.JasperException: No se puede compilar la clase para
JSP
org.apache.jasper.compiler.DefaultErrorHandler.javacError(java.lang.String,
java.lang.Exception) (/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.compiler.ErrorDispatcher.javacError(java.lang.String,
java.lang.Exception) (/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.compiler.Compiler.generateClass(java.lang.String[])
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.compiler.Compiler.compile(boolean, boolean)
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.compiler.Compiler.compile(boolean)
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.compiler.Compiler.compile()
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.JspCompilationContext.compile()
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.servlet.JspServletWrapper.service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, boolean)
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.servlet.JspServlet.serviceJspFile(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse, java.lang.String,
java.lang.Throwable, boolean)
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
org.apache.jasper.servlet.JspServlet.service(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)
(/usr/lib/libjasper5-compiler-5.0.30.jar.so)
javax.servlet.http.HttpServlet.service(javax.servlet.ServletRequest,
javax.servlet.ServletResponse) (/usr/lib/libservletapi5-5.0.30.jar.so)
org.apache.catalina.valves.ErrorReportValve.invoke(org.apache.catalina.Request,
org.apache.catalina.Response, org.apache.catalina.ValveContext)
(/usr/lib/libcatalina-5.0.30.jar.so)
org.apache.coyote.tomcat5.CoyoteAdapter.service(org.apache.coyote.Request,
org.apache.coyote.Response) (/usr/lib/libcatalina-5.0.30.jar.so)
org.apache.coyote.http11.Http11Processor.process(java.io.InputStream,
java.io_OutputStream) (/usr/lib/libtomcat-http11-5.0.30.jar.so)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(org.apache.tomcat.util.net.TcpConnection,
java.lang.Object[]) (/usr/lib/libtomcat-http11-5.0.30.jar.so)
org.apache.tomcat.util.net.TcpWorkerThread.runIt(java.lang.Object[])
(/tmp/libtomcat-util-5.0.30.jar.sodbz2am.so)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run()
(/tmp/libtomcat-util-5.0.30.jar.sodbz2am.so)
java.lang.Thread.run() (/usr/lib/libgcj.so.6.0.0)

In english, "No se puede compilar la clase para JSP", would be "the
class cannot be compiled for JSP".

Does anybody have an idea of what can be happening? I think the error
can be related with the Windows/UNIX difference, but im not sure.

Thank you in advance, and sorry for writing too much code and error
text.
Greetings
 
A

Andrew Thompson

Hi everybody!

Im developing a web application with JSP, .....
public void toLogFile(String fileNameIn, String comentarioIn){
String path = "";
try{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new
FileOutputStream(path + fileNameIn, true)));

A couple of comments.
1) 3 'news' on one line, for code that is failing, is insane.
Break up the lines and print out the result, as the start of
your debugging.
2) Creating a file using new File(path + name) is a bad way to do it
(ignoring
for the moment that your path is ""), instead, use new File(path,
name).
3) Where does this file end up? It seems to be in the 'current
directory',
which is usually not the right place for a web-app. Look into
getRealPath()
to find where your way about a server.

Andrew T.
 

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top