Java Mailing List Archive

http://www.junlu.com/

Google
Google
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
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Oracle Connection Pooling in 3 2 2
Servlet : Session invalidate
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Tomcat and webapplication specific java library path
Running a Simple JMS Example
Mapping in workers2 properties
org apache jasper JasperException
Cannot find message resources under key org apache struts action
   MESSAGE
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
url string for connecting jboss to oracle
Value attribute of <html:checkbox
javax servlet ServletException: BeanUtils populate
HTTP Status 404 The requested resource is not available
5 0 18: Windows XP Pro vs Windows 2000
 
404 error when a newly created file is requested

404 error when a newly created file is requested

2006-12-15       - By Carl

 Back
Reply:     1     2  

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:&nbsp; </FONT><FONT face=Arial
size=2>Tomcat 5.5.17, Windows XP</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Background:&nbsp; 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.&nbsp; Since the
snippets can contain some custom tags, I have a 'Preview' button that reads the
snippet directly from the editor, reads a 'preview'&nbsp;jsp file from the file
system, places the snippet in the correct place in the file, writes the
'preview'&nbsp;file with the snippet to a temporary file and opens a new window
(using javascript) which&nbsp;requests the temporary page from
Tomcat.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Problem:&nbsp; I can see the newly created
temporary file in the file system.&nbsp; I can open it with an editor and it is
all good.&nbsp; But, Tomcat&nbsp;returns a 404 error for approximately one
minute and then will serve the page upon hitting only the refresh.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Analysis:&nbsp; I suspect the system is holding
onto the&nbsp;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>&nbsp;<FONT face=Arial size=2> The relevent parts of the copy
process:</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<BR>&nbsp;&nbsp;&nbsp;&nbsp; File tempFile = File.createTempFile("preview",
".jsp", new
File("C:/projects/EtrakWebApp/web/jsp/tempfiles"));<BR>&nbsp;&nbsp;&nbsp;&nbsp;
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // read
the preview jsp<BR>&nbsp;&nbsp;&nbsp;&nbsp; FileWriter fw = new
FileWriter(tempFile);</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=Arial
size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File
infile = new
File(destinationDir+"preview.jsp");<BR>&nbsp;&nbsp;&nbsp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arial size=2>Anyone have any ideas?</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>TIA,</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Carl Kabbe</DIV></FONT>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</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)

©2008 junlu.com - Jax Systems, LLC, U.S.A.