Please consider this scenario: User should send some files to server and every user has a id. Every user must send the files once, not twice. If a user sends the files and he want to send them again, the file uploading page won't be shown to him. But there is a problem: the uploading process takes time and when the files are being uploaded, user can refresh the page and the page is shown to him (because the files has been not uploaded yet) and then he can upload files again and again!
The client side code using jsp and I cant change it. Now I want to prevent refreshing page in server side. For this purpose, I used a middle page: when a user want to see the file uploading page he goes to this middle page (servlet), this middle servlet puts a flag into user's session and redirect him to file uploading servlet. The file uploading servlet checks the flag and if it exist, the page is shown to him and then flag will be removed. Whenever a user try to refresh the file uploading page, the flag doesn't exist and he will be redirected to an error page.
This was my solution, but it has a serious problem: when user is redirected from middle servlet to file uploading servlet, its request and response will be destroyed and I cant access his request (The user send me some information with his request and I need those in file uploading servlet).
1 - Is there a way to clone request object? (so that I can put in session and after redirect, I can retrieve that)
2- If the answer is no, Is there a better solution for my problem?
Any suggestions would be gratefully appreciated.
Edit:
Please note that I don't want to save the request parameters/attributes into session.
Use window.stop(); in your code.
Related
I am uploading a file in the Servlet, doing the necessary operations on this file, and then downloading this processed file to the client.
I have two forms multipart / form-data. The first one uses the post method to upload files. The second one is using the get method to download the file.
DoPost () -> The user selects and uploads the file. This file is processed and stored in the specified location. And this file is kept as a global variable of type File.
DoGet () -> Downloading the global File.
When a user uploads a file from Web browser, another user can download it from another Web browser.
I suppose this may be the reason that File is global. I tried ThreadLocal, but it did not work because doPost and doGet are not in the same thread.
Is there a way you can suggest?
If the user will upload and download the file in the same session, then you can save the filename in HttpSession during the POST operation. During the GET, you check for the existence in HttpSession. Let the user download the file only if it exists in HttpSession.
If the user could have uploaded the file, then logged out and logged back in and download the file, then you will need to save the file information in some persistence storage like a database.
You are correct each request is a different thread, however they should be linked to the same session.Store your file in the session and all will be sorted.
I have a informative web page in my spring based web application which need to be saved as html/downloaded.
My requirement is to save/ download this opened webpage on click of a button on same page.
I used below code in javascript.
document.execCommand("SaveAs",true,"C:\Saved Content.html");
But this is only working in IE and not in other browsers.
Kindly help on this.
Simply no. JavaScript/Jquery is restricted to perform such operations due to security reasons.
The best way to achieve this, would be, to send a request to the server that would write the new file on the server.
Then from javascript perform a POST request to the server page passing the data you want to write to the new file.
We have some clients that uses IE's Content Advisor and when they switch pages the login pop up appears this because we don't have a call for labels.rdf file on each one of our pages (we have more than 500 pages).
The problem is that Content Advisor tries to search the ICRA's RDF file on the current page but since we don't have this on each page, it tries to search on the same level as index.html file, and we did a change that if this kind of access in this path is made, we clear all user's info, which raises the login page again.
We've already tried to call from index.html file a newly created labels.rdf file just like this:
<link rel="meta" href="http://www.example.org/corporate/labels.rdf" type="application/rdf+xml" />
First we saw that we didn't had access to this RDF file.
But it was fixed.
Then, when testing this, we saw that it never reaches this labels.rdf file, showing the login page again.
Some one knows how Content Advisor works for a workaround here?
In case someone is looking for the solution, use secure cookies for session management. This worked for me.
In my web application I want to create a web-page accessible only to me. Through that page I want to upload photos and other data to my web-app/website. What should I do so that a particular web-page is accessible only to me ?
One way which I think is, reaching that web-page (the page from where I will upload) through another web-page that needs password authentication. But is this the only way and is it a good method ? The authentication will be through a servlet,in case I opt this method .
If you could password protect it, You would only the person who can access that page,
To stop attacks you could also make that page orphan and put it at some weird path so that only you know the path to that page
put Filter specific to that page to check for authenticated session
hash+salt your client name or some unique long number. check it on the server side.
make your app your password and credentials.
We have a form which once submitted a file is created and returned. I created a java method which does the post and a ok status is returned. However how am i able to download the file after the post?
Sorry for not being clear its driving me crazy. We have a business object which generates reports based on parameters sent to it. Once the form is filled in the browser a pop up comes up (save/open) file. What i want to do is create a java standalone program that will sit on my desktop so that when I run this programing (passing it my name and password and URL to post to, this is done already) it will download the file that is created on the server side. The problem is that I don't know where the file is stored (if it is stored) on the server or the name of the file. All i know is that on the browser we go to the form fill it in and the file is returned to the browser. So far the post is working.
When you are on the form in the browser (e.g. http://localhost/my/form) you should inspect the source of the page (IE is Menu View > Source ). In the source you should search for a form tag. This tag contains an action value like:
<form action="myaction.dhtml" method="...>
</form>
So the URL to request is http://localhost/myaction.dhtml and the servers response will be a "file". Good.
You may send the same request that does the browser from Java. To not code all that stuff again you may use a library like HttpComponents.
Probably your form is sending parameters too to the server (user name, password, etc). Look at the form components what parameters the server expect. Your URL may looks like this:
http://localhost/myaction.dhtml?name=Joe;pass=myPassWRD
You don't have to know where the file is stored, but you will need the correct URL that the server will use to take or generate the correct data and send to the client.