aspose file tools*
The moose likes JSP and the fly likes Problem in sequence of actions in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problem in sequence of actions in JSP" Watch "Problem in sequence of actions in JSP" New topic
Author

Problem in sequence of actions in JSP

Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
Hi all,
This is a part of JSP i am developing: Based on user input the array arguments for the java class below differs.

In the above JSP file, i am calling a java class called SOEfile, which actually creates a file called "temp.html" . The java class does lot of file processing, basically it takes input as a array of text files and read each of the files and write them all together in the temp.html.
After that I need to include that temp.html created by the java class in my JSP page. Only after the temp.html is written down fully , it has to be included. The problem is , the JSP shows up the temp.html with old contents in it. It doesn't show up the temp.html with the latest content, if press the submit button the first time, it shows old contents, if i keep pressing it like 3, 4 times, now since the temp.html is written with the new contents, it shows up correctly.
Is there anyway to wait till the actual file is created and then only include it? I think whats happening is : the JSP calls the java class, since the java class is doing lot of file processing, the JSP includes the old temp.html instead of waiting till the file is written down correctly.
Do i need to use threads here? Please let me know how to do this.
Thanks,
Priyha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61609
    
  67

It may be a caching rather than a synchronization problem.
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
But how to solve this? I need some way to wait and then include the file... is there any function that we can use like sleep() or something to just wait for some fixed time and then include the file? Can you any other alternative solutions?
Thanks
Priyha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61609
    
  67

If it's a caching problem, then there's no need to worry about waiting or any other such nonesense.
Before applying a solution, it'd be best to find out what the problem actually is.
Btw, since you know enough about the data to write it out to a file, why bother rather than just streaming it to the JSP output stream?
bear
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
But, tell me why JSP for this problem first hand? I hope a servlet would be a best bet for this kind of situation
Sudharsan
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Are you closing the output file before trying to read from it?


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
Hi guys,
Thanks for your input. The problem is i need to include 13 text files in the JSP, each of the text files has about 8-10 lines. I currently open each of this file and put the lines in a new file with <br> tags for formatted look. If I need redirect the output of each file to out.print statements, then i need to do the file open/close and processing statements in JSP itself, i think its not good to do here.
Also , I am doing many javascript initializations and other things like getting user authentications and checking,etc in the JSP, so i didnt want to do this in a servlet.
Can I do file processing in the JSP itself? or is there any better solution to this?
Thanks
Priyha
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem in sequence of actions in JSP