Connection Broken & Check??
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   bikash_paul
Posted On:   Wednesday, May 21, 2003 06:51 AM

Hi all friends, I am developing one uploading software Iam using Tomcat(servlet) and swing for that.My software working scenario is iam using Tomcat as a centralized server and my user from any computer using swing interface through my Tomcat server they can upload file on any computer on network supplying IP address of that computer in servlet as a parameter with the url of servlet.Now I want that if there is no connection with that computer on which server going to upload file as per user supplied IP address then server should give a error message to user and if connection broken in between file uploading then also server should give error message to user fot that i want to use JOption message box of swing[JOption.ErrorMessage("null","No    More>>

Hi all friends,



I am developing one uploading software Iam using Tomcat(servlet) and swing for that.My software working scenario is iam using Tomcat as a centralized server and my user from any computer using swing interface through my Tomcat server they can upload file on any computer on network supplying IP address of that computer in servlet as a parameter with the url of servlet.Now I want that if there is no connection with that computer on which server going to upload file as per user supplied IP address then server should give a error message to user and if connection broken in between file uploading then also server should give error message to user fot that i want to use JOption message box of swing[JOption.ErrorMessage("null","No Connection);] in servlet file.Can any one plz guide me what will be that code for that.Below r my codes of servlet file:-



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

   <<Less
About | Sitemap | Contact