File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in sequence of actions in JSP

 
Priyha Jootu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It may be a caching rather than a synchronization problem.
bear
 
Priyha Jootu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 319
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1056
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you closing the output file before trying to read from it?
 
Priyha Jootu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic