• Post Reply Bookmark Topic Watch Topic
  • New Topic

copy to app server

 
Juan Zapato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanna now if somebody can explain me easiest way to copy file from some source to app. server and then show it in the browser.
Thanks!
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is your source, at the same machine where you application server located?

-Jignesh
 
Juan Zapato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No on the other maschine but some other class find it I only need to read file from that location temporary save to app server and then show it in new window, so how that servlet finds the file doesn't really metter.
Thks!
 
Juan Zapato
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I try it something like this:

<code>

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ProbServlet extends HttpServlet{

public void processImpresion(HttpServletRequest req, HttpServletResponse res) throws Exception {

String fileName = null;
String pdfBasePath = null;

fileName = something.getFileName();


File filePdf = new File(fileName);

FileInputStream fInp = new FileInputStream(filePdf);


FileOutputStream fOut = new FileOutputStream(getServletContext().getRealPath("")+System.getProperty("file.separator")+"pdf"+System.getProperty("file.separator")+fileName);
int BUFFER = 1024;
int count=0;
byte data[] = new byte[BUFFER];
BufferedInputStream bis = new BufferedInputStream(fInp,BUFFER);
while ( (count = bis.read(data, 0, BUFFER)) != -1)
{
fOut.write(data, 0, count);
}
fOut.flush();
fOut.close();
res.setContentType("application/pdf");
req.getRequestDispatcher("pdf/" + fileName).forward(req,res);
}

}
</code>
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand what you are trying to convey.

But I can think in this scenario.

You need to have 2 application 1 at on machine where the file located and the other 1 is your appserver.

They both can communicate either by using java.net api. Socket and ServerSocket communication. In this case you can directly communicate via streams

RMI communication.

File transfer through http protocol. In this case you need to save file at perticular location at your AppServer and then you have to read as mentioned in your servlet.

Using web services(ie. by passing xml files)
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are some free applications available on the net if you search. Which provides file search utility. You can think of downloding that software on other machine and then invoking through your server application.

You may wanna look at following thread:
http://forum.java.sun.com/thread.jspa?threadID=222415&messageID=816464
[ July 24, 2005: Message edited by: Jignesh Patel ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!