Hi all,
In my project i need to download the file to the client machine from my server, Below is the code, its downloading the file but saving the file in the server itself. I want it to save in the client machine. Pls help me out guys. Im not getting where im going wrong.
<%@ page language="java"
import="java.lang.*,java.io.*, com.utils.*,
java.sql.*,
listener.*,java.net.URL,java.net.URLConnection" %>
<%@ include file="Connection.jsp" %>
<%
String path = request.getContextPath();
String basePath =
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
// Check for valid session
if (session.getAttribute("logged") ==
null)
response.sendRedirect("../htmls/InvalidSession.html");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN">
<HTML>
<HEAD>
<link rel="stylesheet"
type="text/css" href="../styles/Portal.css">
</HEAD>
<BODY>
<%
String repoDir =
request.getParameter("repoDir");
String fileName =
request.getParameter("fileName");
String docId =
request.getParameter("fileId");
String folderName =
request.getParameter("folderName");
%>
<%
String docPath = "";
String outdocPath = "";
DataInputStream in=null;
DataOutputStream ffout=null;
FileOutputStream fOut=null;
docPath="http://webdevelop-5:8080/Maddy/" + repoDir +
"/" + folderName + "/" + fileName;
//basePath + repoDir + "/" +
folderName + "/" + fileName;
try
{
URL remoteFile=new URL(docPath);
URLConnection
fileStream=remoteFile.openConnection();
// Open the input streams for the
remote file
fOut=new
FileOutputStream("c://"+fileName);
// Open the output streams for saving
this file on disk
ffout=new DataOutputStream(fOut);
in=new
DataInputStream(fileStream.getInputStream());
int data;
while((data=in.read())!=-1){
fOut.write(data);
}
in.close();
fOut.flush();
fOut.close();
}
catch(Exception e)
{
%>
<
jsp:forward
page="MessagePage.jsp">
<jsp
aram name="mess" value="<%=e.toString()%>" />
<jsp
aram name="messType" value="Error" />
<jsp
aram name="title" value="Error Message" />
</jsp:forward>
<%
}
%>
<a href ='mailto:?subject=Company
news&attachments=""c:\<%=fileName%>""'>email</a>
</BODY>
</HTML>