Results 1 to 4 of 4
Thread: Need help in logic
- 03-23-2011, 03:49 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 85
- Rep Power
- 0
Need help in logic
I have a word cloud app which generates a image based upon user input text. This generated image is stored in images folder. I have provided a save image option which allows user to save this image on their desktop. I am doing this by calling a servlet shown below which reads the image stored & writes to byte stream.
Problem with this approach is, if another user (user 2) meantime generates a word cloud, it replaces output.png with this new image. Now if user 1 tries to save the image, he gets an wrong image(image of user 2).Java Code:protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setHeader("Content-disposition","attachment; filename=output.png"); String filename = request.getSession().getServletContext().getRealPath("/")+"/images/output.png"; String mimeType = "image/png"; response.setContentType(mimeType); File file = new File(filename); response.setContentLength((int)file.length()); FileInputStream in = new FileInputStream(file); OutputStream outputStream = response.getOutputStream(); byte[] buf = new byte[1024]; int count = 0; while ((count = in.read(buf)) >= 0) { outputStream.write(buf, 0, count); } in.close(); outputStream.close(); }
Can you please suggest me a better approach which will allow to keep images user specific?
- 03-23-2011, 04:12 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
Don't store it in a folder, use a database instead?
Is there a way of identifying a particular user?
Do they log in?
Or is it only via a session id?
- 03-23-2011, 06:23 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 85
- Rep Power
- 0
yes, i have the user logged in details. But I guess storing every image in the DB would be an overhead. Is it possible to store image in a session & then retrieve it while saving it. If yes, please let me know how.
- 03-23-2011, 06:44 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,458
- Rep Power
- 16
Similar Threads
-
Formula Logic Help
By sehudson in forum New To JavaReplies: 4Last Post: 03-11-2011, 04:17 AM -
Need help on logic
By nn12 in forum New To JavaReplies: 6Last Post: 03-10-2011, 11:06 AM -
Logic not working
By Prajin in forum AWT / SwingReplies: 1Last Post: 07-19-2010, 07:54 PM -
need a logic for this
By rajivjoshi in forum New To JavaReplies: 4Last Post: 06-12-2010, 02:18 PM -
Cant get the logic right
By jermaindefoe in forum New To JavaReplies: 4Last Post: 03-11-2008, 12:22 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks