• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying servlet output immediately

 
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I have written a servlet that reading and inserting records into database in shape of loop. When loop finishes then it showing the results that's taking too long to display the results.
I am interested to show the result while the loop is running

Is there a way around?

Thanks & best regards
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would need to use Ajax for that.

Is the last query taking to long? Or all the process take too much time?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at this thread for a related question.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hebert Coelho wrote:You would need to use Ajax for that.


Can you please refer me to a Ajax tutorial/example website where I can overcome this issue

Is the last query taking to long? Or all the process take too much time?


Its a loop that reading files and inserting them into DB that may be one or 10K. Its probably time consuming task

Thanks & best regards
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:Have a look at this thread for a related question.


Thanks Paul your post is useful but want to clear some points


The initial request starts a thread running and puts a reference to the thread, or to some proxy for the thread, into the user's session.
Subsequent requests get the thread from the session. If it is still alive, the response says "Still running", otherwise the response says "Finished".


Please correct me if I am wrong that for saving browser timeout when the loop starts I add something in session to prevents page timeout?

Of course you can expand on this basic structure to return the result of the long-running process, or to return the percentage complete if the long-running process can produce that information.


Here its a problem that its showing percentage complete after doing all processes done that I want to fix it

Thanks again and best regards
 
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how you want to display?
do you want to display as graph? or you want to display the content what you are inserting into the data base?
and most important thing is how much data you want to display?
if you want to display the data while inserting, it is very easy to display the data, you don't have to make a call at all,
when it comes to the fetching the data an you want to display the data then it would take long time to display, to it's all about the how much data you want to display
if your question some more specific, the it'll be easy to give the solution, if it is possible post the servlet code.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks tinku for your favorable reply

The user will upload a zip file and my code will:
1) unzip the file
2) Check the file extensions if they are doc,docx or pdf
3) Code will parse file and convert into XML
4) Then XML tags will be converted into variables
5) Here will check from DB either email or Tel exists or not. if exists reject the file otherwise
6) Insert into DB
7) if successfully inserted then display message inserted successfully

all this will run in a loop to read the file and loop may be in thousands (files).

I just want to show the messages of:
1) Already exists
2) Inserted into DB successfully

but my code displays these messages when it finishes all the tasks within loop not print the messages for files one by one

Thanks again
 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it seems you are using the same servlet to generate the display view purpose also, this is happening because when the execution of the servlet completes then only we gets the view
it is not possible to get the view from the servlet in the middle of the execution and once again go back to the execution point, all container generates the view after complete execution of the servlet.


 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tinku rider wrote:it seems you are using the same servlet to generate the display view purpose also, this is happening because when the execution of the servlet completes then only we gets the view
it is not possible to get the view from the servlet in the middle of the execution and once again go back to the execution point, all container generates the view after complete execution of the servlet.



This is what am looking for. Is that could be implemented?

Thanks again
 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how you want to generate the view? you have to explain in detail then only i can help you out
in the sense do you want to give the alert box to the user?

this can be implemented using Filters,Ajax and Comet, you have to use the these three component to generate your requirement
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tinku rider wrote:how you want to generate the view? you have to explain in detail then only i can help you out
in the sense do you want to give the alert box to the user?



Can we generate simple text/html page view instead of alert box?

thanks again for giving me your precious time
 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This can be implemented using Filters,Ajax and Comet, you have to use the these three component to generate your requirement.

 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you please refer any example/tutorials that is nearest to my situation?

thanks again
 
hemantha kumar k
Greenhorn
Posts: 27
Hibernate jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. when you want to display the massage save massage in Request Attributes
2. Using the ServletRequestAttributeListener to listen the changes and use Comet push the data to clientside


comet is the technique pushing the data from server side to client side without receiving request from the client side

http://martin.ankerl.com/2007/08/21/ajax-dojo-comet-tutorial/

this is the link about example of coment it won't fully solve your problem. but it solves the part of your problem
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tinku rider I am thankful to you from the bottom of my heart. I am studying the both referred docs

Best regards
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
For showing you the data use navigation so have to read and insert a large data at once.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

sorry for late reply

I tried this example and html page and its working fine. I have written my servlet as follow:

but getting this error:


Thanks again
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Didn't you solve that yesterday in this thread?
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob Spoor for replying but yesterday was trying to solve another case. By inserting public class now its throwing the following exception


Thanks again
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The stack trace says the error occurs on line 21. There are two references there: Bayeux b and Channel c. As b has already been successfully used before (on line 16), that means that your Channel is null.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob Spoor from the bottom of my heart.

Best regards
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:There are two references there: Bayeux b and Channel c. As b has already been successfully used before (on line 16), that means that your Channel is null.


Thanks again for continously helping me



but same NPE:


When I test as html + push servlet then its working fine

Thanks again & best regards
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May I open as a new question as this is marked resolved?
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It isn't anymore.

Since you don't seem to know how exception stack traces work I'll give you a little lesson.

The stack trace starts with the exception class name and message (if not null). In this case that's java.lang.NullPointerException. Below that is the exact chain of method calls, the last called method first. This is the method that is actually throwing the exception. Behind it is the file name and line number of the source code where the exception came from. In this case that's BulkUpload.doPost(BulkUpload.java:116) - line 116 of file BulkUpload.java. Since this is your own class, you don't need to look any further; you've found the exact line where the problem occurs. Now all you need to do is figure out which variable on that line is null.

Sometimes the top of the stack trace isn't your code but someone else's; sometimes even the core API. This can mean there is a bug in that code, but more often you're calling some method with incorrect arguments. You then move to the second, third, fourth etc line until you hit a line that indicates your code. That's where you've supplied an incorrect arguments.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I seen line No. 116 and this line is:

That's why I sorted help with comet by posting my code

Regards
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c is still null.
 
Farakh khan
Ranch Hand
Posts: 851
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I open Channel manually? this will fix my problem

regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic