I noticed in the code, you send an error message on a GET method, when
actually you could call the POST method in GET.
----------------
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
doPost(request, response);
}
--------------------
Deepak
-----Original Message-----
From: Bikash Paul [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 3:47 AM
To: [EMAIL PROTECTED]
Subject: Newbie Question??
Hi all friends,
Iam developing one application(front end swing , back
end servlet and http protocol through urlconnection)
for data transfer from one destination to another.And
application have facility of suspend of one file in
between and start another new file from scratch and
can resume that file which is stopped in between
later.Now for that I want to put condition in servlet
so that it can recognise two situation:-
1.if it is new file it can write in the file and
2.if it is partial file it can append into the file by
opening the file in append mode.
But I couldn't decide what will be the syntax of
condition.Can any one plz suggest me how i can put
conditions.Any help will be highly appreciated.Below r
my codes:-
RecvServlet.java:-
=================
public class RecvServlet extends HttpServlet {
public static final String BASE_DIR = "d:\\temp";
File baseFile;
public void init() throws ServletException {
super.init();
baseFile = new File(BASE_DIR);
}
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
{
String filename;
filename = request.getParameter("name");
String path;
path = request.getParameter("path");
File outfile = new File(filename);
if (path != null && filename != null) {
outfile = new File(path, filename);
System.err.println("Final output file: " +
outfile.getAbsolutePath());
}
DataInputStream dis;
dis = new DataInputStream(request.getInputStream());
OutputStream os;
os = new BufferedOutputStream(new
FileOutputStream(outfile));
int cc;
byte [] buf = new byte[512];
long lim, tot = 0;
lim = dis.readLong();
try {
System.err.println("Reading " + lim + " bytes...");
for(cc = dis.read(buf, 0, 512);
cc > 0 && tot < lim;
cc = dis.read(buf, 0, 512))
{
os.write(buf, 0, cc);
tot += cc;
System.err.print("+" + cc + "(" + tot + ")");
if (tot >= lim) break;
}
}
catch (IOException ie) {
try { os.close(); } catch (Exception e2) { }
System.err.println("Exception during file transfer!");
}
System.err.println("Read " + tot + " bytes.");
os.close();
response.setContentType("text/plain");
PrintStream pos = new
PrintStream(response.getOutputStream());
pos.println(tot);
}
}
Regards
Bikash
__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.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
___________________________________________________________________________
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