Writting confirmation message??
Bikash Paul <[email protected]>
| Newsgroups | gmane.comp.java.sun.servlet |
|---|---|
| Message-ID | <[email protected]> |
Hi all friends,
I am developing one uploading software it is a total
automatic process of uploading user only copy the
files in predefind folder and click on upload button
once and my software starts uploading one by one from
queue and move the file one by one into another folder
automatically after completion of uploading.After that
in between uploading if user copy more files in that
folder my software automatically takes those file for
uploading not require to click on upload button
again.Now I am facing problem on writing confirmation
message of uploading of every file on my swing
interface which my servlet writing on PrintStream
after completion of writing of every file on
destination.But my interafce not writing those
confirmation messages on textArea but it is writing
confirmation message of last file on Dos-Prompt coz
iam running my application from Dos-prompt.I want to
write every file's uploading confirmation message on
textArea of my swing application.Can any one plz guide
me how I can do that.Below r my codes:-
swing application(Iam pasting those portion only):-
===================
class Loglater implements Runnable {
String msg;
public Loglater(String s) { msg = s; };
public void run() { log(msg); }
}
public void log(String msg) {
if (SwingUtilities.isEventDispatchThread()) {
textArea.append(msg);
textArea.append("\n");
System.err.println(msg);
}
else {
SwingUtilities.invokeLater(new Loglater(msg));
}
return;
}
servlet:-
========
import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
public class RecvFileServlet extends HttpServlet {
String s,str,str1,filename,path;
public void init() throws ServletException {
super.init();
baseFile = new File(BASE_DIR);
str="false";
str1="false";
}
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.sendError(response.SC_NOT_ACCEPTABLE, "Must
use POST method.");
}
public void doPost(HttpServletRequest
request,HttpServletResponse response)
throws ServletException, IOException
{
PrintStream pos = new
PrintStream(response.getOutputStream());
response.setContentType("text/plain");
filename = request.getParameter("name");
path = request.getParameter("path");
File outfile = new File(filename);
System.out.println("path value = " + ((path ==
null)?("null"):(path)));
System.out.println("name value = " + ((filename ==
null)?("null"):(filename)));
if (path != null && filename != null) {
outfile = new File(path, filename);
System.err.println("Final output file: " +
outfile.getAbsolutePath());
}
// create a DataInputStream to read from sender
DataInputStream dis;
dis = new DataInputStream(request.getInputStream());
OutputStream os;
// create file output stream to write the output file
System.err.println("Using output file " + outfile);
os = new BufferedOutputStream(new
FileOutputStream(outfile));
int cc;
byte [] buf = new byte[1024];
long tot = 0;
// read from the input stream and write to the file
try {
for(cc = dis.read(buf, 0, 1024);cc > 0 ; cc =
dis.read(buf, 0, 1024))
{
os.write(buf, 0, cc);
tot += cc;
System.err.print("+" + cc + "(" + tot + ")");
}
}
catch (IOException ie) {
try { os.close(); } catch (Exception e2) { }
pos.println("Problem : " + ie.getMessage());
}
// done reading and writing, close the file output
stream
System.err.println("Write" + tot + " bytes.");
os.close();
// Send back a response message to the application
pos.println("File" +" "+ filename+" "+"Upload
Completed !");
}
}
Regards
Bikash
__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com
___________________________________________________________________________
To unsubscribe, send email to [email protected] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html