We do not want to open file directly from context.
For which we write a servlet to open file.
code is.


/*
 * Created on Jan 31, 2008
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package org.appfuse.supportclasses;

import java.io.IOException;

import javax.servlet.ServletException;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

/**

* @version 1.0

* @author

*/

public class ToOpenFile extends HttpServlet {


/**

* @see javax.servlet.http.HttpServlet#void
(javax.servlet.http.HttpServletRequest,
javax.servlet.http.HttpServletResponse)

*/

public void doGet(HttpServletRequest req, HttpServletResponse resp)

throws ServletException, IOException {

String fn = "WordFile.doc";

resp.setHeader("Content-type","application/x-download"); 

resp.setHeader("Content-disposition","inline; filename=\"" + fn + "\"" );

System.out.println("QueryString " + req.getAttribute("filePath"));


FileInputStream is = new FileInputStream("E:\\J2EE Developer_Anupam.doc");

int read=0;

byte[] bytes = new byte[1024];

OutputStream os = resp.getOutputStream();

//OutputStream os = new FileOutputStream("sub_MT_03.jpg");

if(is == null)

System.out.println("IS is null");


while((read = is.read(bytes)) != -1)

{

os.write(bytes, 0, read);

}

os.flush();

os.close();


}

}


This workds fine when we direct call to open file.
But when we call it through action then it open file in with garbeled
character.
The reason may be due to deafult.jsp where where some files are included
,responsetype are set.
but when by pass deault.jsp then blank file opens.
please give us the solution.



-- 
View this message in context: 
http://www.nabble.com/problem-with-servlet-to-open-file.-tp15225215s2369p15225215.html
Sent from the AppFuse - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to