Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript Java JSP
Hi, I have written a code to save an exe file from my server side to client's pc in C:\ drive.
But, I am getting error as like this:
 
type Exception report
 
message
 
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
 
exception
 
java.lang.OutOfMemoryError: Java heap space
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.2.2 logs.

 
For my code:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"  %> 
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% 
String fileName=getServletContext().getRealPath("jdk-6u20-windows-i586.exe"); 
 
File f=new File(fileName); 
 
InputStream in = new FileInputStream(f); 
 
BufferedInputStream bin = new BufferedInputStream(in); 
 
DataInputStream din = new DataInputStream(bin); 
StringBuffer sb=new StringBuffer(); 
while(din.available()>0) 
    { 
    sb.append(din.readByte()); 
    } 
 
try {    
    PrintWriter pw = new PrintWriter(new FileOutputStream("c:/jdk-6u20-windows-i586.exe"));// save file 
    pw.println(sb.toString()); 
    pw.close(); 
} catch(IOException e) { 
   e.getMessage(); 
} 
          
in.close(); 
bin.close(); 
din.close(); 
%> 
    </body>
</html>
Please help me to solve this problem. And if I want to add a progress bar to display count % for downloading file than what I have to do for this in my code. Can you help me brother?
Posted 5-Apr-13 21:50pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

No Popular browser will give you access to Client's local file system
In this case you can provide a link to file by putting it in your project folder or GlassFish Server folder
or else you case use a signed applet
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 390
1 Jochen Arndt 165
2 Richard MacCutchan 135
3 DamithSL 95
4 Garth J Lancaster 90
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,032
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,220


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 21 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100