  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | 404 error when a newly created file is requested | 404 error when a newly created file is requested 2006-12-15 - By Carl
Back Environment: Tomcat 5.5.17, Windows XP
Background: I have a jsp page that contains a javascript rich text editor that I use to create snippets of HTML code that are stored in a database and later displayed on other pages. Since the snippets can contain some custom tags, I have a 'Preview' button that reads the snippet directly from the editor, reads a 'preview' jsp file from the file system, places the snippet in the correct place in the file, writes the 'preview' file with the snippet to a temporary file and opens a new window (using javascript) which requests the temporary page from Tomcat.
Problem: I can see the newly created temporary file in the file system. I can open it with an editor and it is all good. But, Tomcat returns a 404 error for approximately one minute and then will serve the page upon hitting only the refresh.
Analysis: I suspect the system is holding onto the newly written file until it hits some timeout but I have tried everything I can think of to make certain the file has been 'released'. The relevent parts of the copy process:
try { File tempFile = File.createTempFile("preview", ".jsp", new File("C: /projects/EtrakWebApp/web/jsp/tempfiles")); // read the preview jsp FileWriter fw = new FileWriter(tempFile);
File infile = new File(destinationDir+"preview.jsp"); if( infile.exists() ) { FileReader fr = new FileReader(infile); BufferedReader in = new BufferedReader(fr); while(true) { String line = in.readLine(); if( line==null ) break; System.out.println("line "+line ); // insert the text if( line.contains("insert_preview_text") ) { fw.write(previewText+"\n"); } else { fw.write(line+"\n"); } } fr.close(); in.close(); } fw.flush(); fw.close(); fw = null; } catch (FileNotFoundException fnf) { fnf.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } return returnFileName;
Anyone have any ideas?
TIA,
Carl Kabbe
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META http-equiv=Content-Type content="text/html; charset=iso-8859 (See http://iso-8859.ora-code.com)-1"> <META content="MSHTML 6.00.2800.1106" name=GENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=#ffffff> <DIV><FONT face=Arial size=2>Environment: </FONT><FONT face=Arial size=2>Tomcat 5.5.17, Windows XP</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Background: I have a jsp page that contains a javascript rich text editor that I use to create snippets of HTML code that are stored in a database and later displayed on other pages. Since the snippets can contain some custom tags, I have a 'Preview' button that reads the snippet directly from the editor, reads a 'preview' jsp file from the file system, places the snippet in the correct place in the file, writes the 'preview' file with the snippet to a temporary file and opens a new window (using javascript) which requests the temporary page from Tomcat.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>Problem: I can see the newly created temporary file in the file system. I can open it with an editor and it is all good. But, Tomcat returns a 404 error for approximately one minute and then will serve the page upon hitting only the refresh.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2>Analysis: I suspect the system is holding onto the newly written file until it hits some timeout but I have tried everything I can think of to make certain the file has been 'released'.</FONT> <FONT face=Arial size=2> The relevent parts of the copy process:</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2> try {<BR> <BR> File tempFile = File.createTempFile("preview", ".jsp", new File("C:/projects/EtrakWebApp/web/jsp/tempfiles"));<BR> <BR> // read the preview jsp<BR> FileWriter fw = new FileWriter(tempFile);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=Arial size=2> File infile = new File(destinationDir+"preview.jsp");<BR> <BR> if( infile.exists() )<BR> {<BR> FileReader fr = new FileReader(infile);<BR> <BR> BufferedReader in = new BufferedReader(fr);<BR> <BR> while(true)<BR> {<BR> String line = in.readLine();<BR> <BR> if( line==null )<BR> break;<BR> <BR> System.out.println("line "+line );<BR> <BR> // insert the text<BR>   ; if( line.contains("insert_preview_text") )<BR> {<BR> fw.write(previewText+"\n");<BR> }<BR> else {<BR> fw.write(line+"\n");<BR> }<BR> }<BR> <BR> fr.close();<BR> in.close();<BR> }<BR> <BR> fw.flush();<BR> fw.close();<BR> fw = null;<BR> }<BR> catch (FileNotFoundException fnf)<BR> {<BR> fnf.printStackTrace();<BR> }<BR> catch (Exception ex)<BR> {<BR> ex.printStackTrace();<BR> }<BR> <BR> return returnFileName;<BR></FONT></DIV> <DIV><FONT face=Arial size=2>Anyone have any ideas?</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>TIA,</FONT></DIV> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2>Carl Kabbe</DIV></FONT> <DIV><FONT face=Arial size=2></FONT> </DIV> <DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>
No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.409 / Virus Database: 268.15.19/587 - Release Date: 12/14/2006
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To start a new topic, e-mail: users@(protected) To unsubscribe, e-mail: users-unsubscribe@(protected) For additional commands, e-mail: users-help@(protected)
|
|
 |