Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2006

Tip: Looking for answers? Try searching our database.

Problem creating text files with JSP

Thread view: 
miguelcampoy@hotmail.com - 16 Oct 2006 19:50 GMT
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[i].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
Andrew Thompson - 17 Oct 2006 05:16 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.