Hi,
I have one interface on swing iam trying to select
file from hard drive through one button and passed it
to servlet through url connection.It is working
perfectly.Now I want to set destination folder for
saving that file which I select for upload.For that I
add below programme in action of button for select
file.
In Swing programme:-
---------------------
.............
.............
.............
Button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try{
JFileChooser fc = new JFileChooser();
fc.setDialogTitle("Choose a File");
int ee=fc.showDialog(contentPane,"OK");
if (ee==1)return;
File a=fc.getSelectedFile(); String
aa=a.getAbsolutePath();
byte buff[]=new byte[(int)a.length()];
InputStream fileIn=new FileInputStream(aa);
int i=fileIn.read(buff);
String conffile=new String(buff);
URL url;
URLConnection urlConn;
DataOutputStream printout;
// URL of CGI-Bin script.
url = new URL
("http://127.0.0.1:7001/servletUpload1?PATH=aa1");
// URL connection channel.
urlConn = url.openConnection();
// Let the run-time system (RTS) know that we want
input.
urlConn.setDoInput (true);
// Let the RTS know that we want to do output.
urlConn.setDoOutput (true);
// No caching, we want the real thing.
urlConn.setUseCaches (false);
// Specify the content type.
urlConn.setRequestProperty("Content-Type","multipart/form-data);
printout = new DataOutputStream
(urlConn.getOutputStream ());
String qry = URLEncoder.encode("qry")+"="+
URLEncoder.encode(qryString);
printout.writeBytes (content);
printout.flush ();
printout.close ();
// Get response data.
BufferedReader input = new BufferedReader (new
InputStreamReader(urlConn.getInputStream ()));
String str;//("");
while ((str = input.readLine())!=null)
{
textArea.append(str);
textArea.append("\n");
}
input.close ();}
catch (MalformedURLException k) { // new URL()
failed
} catch (IOException k) { //
openConnection() failed
}
}
});
And I try to select the destination folder on another
button action:-
-------------------------
button.addActionListener(new ActionListener() {
public void
actionPerformed(ActionEvent e) {
try{
JFileChooser fc1 = new JFileChooser();
fc1.setDialogTitle("Choose a DestinationFile");
int ee1=fc1.showDialog(contentPane,"OK");
if (ee1==1)return;
File a1=fc1.getSelectedFile(); String
aa1=a1.getAbsolutePath();
}
catch(Exception e1){}
}
});
And try to pass it to servlet:-
---------------------------------
url = new URL
("http://127.0.0.1:7001/servletUpload1?PATH=aa1");
In my servlet programme:-
--------------------------
// Save the file with the original name
// in a virtual path of the web server
count =
mySmartUpload.save(mySmartUpload.getRequest().getParameter("PATH"));
But it not saving selected file in destination
folder.Plz guide me where I done a mistake.But if I do
hard code for destinatin path.Then it is work fine.
Like below:-
count = mySmartUpload.save("//Machine
name/directory");
Iam trying do it locally that menas in local network
connected machine.
Thanks for ur valuable time
Bikash
__________________________________________________
Do You Yahoo!?
Find the one for you at Yahoo! Personals
http://personals.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