Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Angel J Gama

Ranch Hand
+ Follow
since Jun 28, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Angel J Gama

To cancel an upload, just change the src of the iframe you're doing the uploading work... For example:



Hope this helps
Hi,

I've a working application where the user upload multiple files at the same time, all this through the use of apache's fileupload, HTML DOM and iframe submits (there's one html form per file to be uploaded, and one iframe per html form... in fact I NEED it this way).

I decided to feedback the user with the upload progress, so I implemented ProgressListener, set a progress listener within the servlet that uploads the file, and use ajax calls in the jsp to get the percent uploaded. By the way, in the servlet I set one progress listener per file and store it in the user's session, in that way I can track the uploading progress for each file.

I use ajax to get the percent uploaded of each file, and a javascript timeout to call this ajax function. Once I got the ajax response, I write the upload progress within a div.

When I submit one file, the upload progress is successfully updated within the div. I can actually see 0%, 5%,...25%,..56%...82%... 100%

The thing is that, for some unknown reason (to me), whenever I submit more than one file, the div isn't updating with the progress of each file... it's just updated sometimes 'twice': when the first file has been submited, and when a file (1st, 2vd, 3rd, ...) has been uploaded.

The ajax call to get the upload percent, is being called every second. What happens when I call the servlet 'A' with AJAX, and in the middle of this I called one more time servlet 'A' (in this 2nd time I track another progresslistener)? Does the first request stop serving?
Any ideas how to show the upload progress of each file if I'm using a form and iframe per file?

Thank you!
[ September 18, 2008: Message edited by: Bear Bibeault ]
13 years ago
Hi,

I've an application where the user upload multiple files at the same time, all this through the use of apache's fileupload, HTML DOM and iframe submits (there's one html form per file to be uploaded, and one iframe per html form).
I decided to feedback the user with the upload progress, so I implemented ProgressListener, set a progress listener within the servlet that uploads the file, and use ajax calls in the jsp to get the percent uploaded. By the way, in the servlet I set one progress listener per file and store it in the user's session, in that way I can track the uploading progress for each file.
I use ajax to get the percent uploaded of each file, and a javascript timeout to call this ajax function. Once I got the ajax response, I write the upload progress within a div:

So, just to have the idea of what I've coded in the jsp:




When I submit one file, the upload progress is successfully updated within the div. I can actually see 0%, 5%,...25%,..56%...82%... 100%

The thing is that, for some unknown reason (to me), whenever I submit more than one file, the div isn't updating with the progress of each file... it's just updated sometimes 'twice': when the first file has been submited, and when a file (1st, 2vd, 3rd, ...) has been uploaded.

Mmm.. so, How does upload multiple files work?

The ajax call to get the upload percent, is being called every second. What happens when I call the servlet 'A' with AJAX, and in the middle of this I called one more time servlet 'A' (in this 2nd time I track another progresslistener)? Does the first request stop serving?
Any ideas how to show the upload progress of each file if I'm using a form and iframe per file?

Thank you!
13 years ago
My suggestion is to stream the file upon demand. If the record you're going to include in the file is likely to change, you could create a temporary table where you can store a copy of that record. Later, you can delete the temporary record instead of a file.
I feel that much secure, and probably space-saving.
13 years ago
Once you commit the response, there is no other thing to commit later.
And when you've commited the response, it'll be sent back to the client. But if you commit the response and then you try to do something with it, then you'll get the IlegalStateException.
If you stop the chain -no call to chain.doFilter()- no other filters are executed, and that makes sense because the chain object knows what resource is in stack (filter, servlet, ...)
[ August 31, 2008: Message edited by: Angel J Gama ]
13 years ago
I'm using servlet spec 2.5 (tomcat 6.x)...

would it be a good "practice/convention" to code <servlet> tags first, and then <servlet-mapping> tags?
Thanks
13 years ago
Hi,
I was reading the Invoker Servlet FAQ and it says that:

...
The Middling Tale
...
Order of elements in web.xml is very important. So when you go to create your second 'couplet', make sure all your <servlet> tags are declared before your <servlet-mapping> tags. You'll maybe want to keep the 'couplets' together, because it will be easier to see which one belongs to which, but don't do it!


I've been writing the <servlet-mapping> tag just after its own <servlet> tag and I haven't had problems.
Does any one knows why don't keep 'couplets' together?
[ August 31, 2008: Message edited by: Angel J Gama ]
13 years ago
Very "nice" Bear Bibeault.
13 years ago
Yes Bear Bibeault,
I've read that... have you read my post? response.setHeader(...) isn't working in my servlet.
13 years ago
Using iframes isn't ajax. It's just sending the form in another "window".
YOu could use the same JS function, but instead of append an input file within a div, you can so something like this:
It's probable that I've misspelled some js methods, but that's a way to do it (no ajax).
I think your best option would be to use <security-constraint> tag in web.xml
There you can state in what url-patterns and servlets the user must have logged-in before accesing them.
And use <login-config> tag to specify the login and login-error page.
Check head first servlets & jsp book, it's explained very well in there. I think there's a tutorial at javaranch but I'm not sure.
13 years ago
I didn't hear that... I'm living it!!!
Here's my situation:

Servlet "/servlet/panel.do"
- retrieves records from database and stores them into a request attribute.
- set header "control-cache" with value "no-cache".
- use requestDispatcher to forward request and response to page "/panel.jsp"

JSP "/panel.jsp"
- Gets the request attribute and creates a table with this info.
- There's a link to another servlet "/servlet/editUser" to edit user's info.

Servlet "/servlet/editUser"
- Gets the record from the database and store it into a request attribute
- set header "control-cache" with value "no-cache".
- Use requestDispatcher to forward request and response to page "/editUser.jsp"

JSP "/editUser.jsp"
- User updates the info (html form) and submits through an iframe.
- servlet "/servlet/updateUser" updates the info and writes into response some text
- JSP reads this response and use javascript to do location.replace("/servlet/panel.do")

Once again in panel.jsp, the information shown is from cache :S So response.setheader before forwarding with requestDispatcher didn't work.


- Any ideas?
- What practice can I use to prevent response from being cache (in my scenario)?
- what practices to prevent response from being cache exists?
13 years ago

Since I'm using a requestDispatcher, I can't use response.setHeader.

Ok, I didn't explain myself... In the servlet I can do response.setHeader and then use requestdispatcher to forward request and response, but doing that I can't prevent the response from being cache, isn't it?

My questions are:
- What practice can I use to prevent response from being cache (in my scenario)?
- what practices to prevent response from being cache exists?
13 years ago
I mean, using requestDispatcher I can't prevent page cache by setting response headers. I tried doing this but it was unsuccessful

Is there any other thing I can do in the servlet to prevent from being cache its response?

What would be the best practice to avoid/prevent the response from being cache for my scenario?
Thanks a lot!
13 years ago

If I understood your question correctly.

the forward and include methods in RequestDispatcher takes response as a parameter.

You are right, but I'm forwarding it (or them: request and response) to another resource, so the response has not been commited yet. Even if I set headers in the response, they won't be commited at this time.
13 years ago