This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes I/O and Streams and the fly likes connecting and copying files in tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "connecting and copying files in tomcat " Watch "connecting and copying files in tomcat " New topic
Author

connecting and copying files in tomcat

Yinka Olicks
Greenhorn

Joined: Aug 28, 2004
Posts: 12
hello Ranchers,
Sorry to botjer you all but,I have a project I am working on,the application is web based so I am using jsp as the frontend tomcat as the application server,and Oraqcle/mysql as the database.
Now the scope of the program is to use the jsp page from a client system to connect to a bean which does the database connection,now when the user clicks on a button on the jsp page its suppose to trigger the bean to pick up the path to a file from a column in the databse which is on a server in a different system/environment.If path is found it follows the path to pick up the file which could also be in a different environment/system and copies it back to a folder on the server system I am not supposed to use ftp and I have tried a couple of thins and I keep on getting errors here is a sample of the last code I used and error

package empire;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import java.sql.*;


public class GetFile2
{
private String list=null;
private String id=null;
private String pref=null;
private String url=null;
private String fpath=null;
Connection connect = null;
ResultSet result = null;
PreparedStatement state = null;
Socket s;
ServerSocket ss;


public void setlist(String list)
{

this.list=list;
}
public void setid(String id)
{

this.id=id;
}
/* public void setpref(String pref)
{

this.pref=pref;
} */


public String getlist()
{
return list;
}

public String getid()
{
return id;
}
/* public String getpref()
{
return pref;
} */

public GetFile2() throws ClassNotFoundException
{
Class.forName("com.mysql.jdbc.Driver");

}
public void getSocket(Socket s)
{
this.s=s;
}
public boolean AccountValidate()
{
boolean validate=false;
String list1="";
String id1="";
String pref1="";
try{

list=getlist();
id=getid();
//pref=getpref();


connect=DriverManager.getConnection("jdbc:mysql://localhost/empire?user=roy&password=arsenal");
state=connect.prepareStatement("Select * from CLIENTS_TAB where CLIENT_ID='"+id+"'");
//String strQuery = "Select * from clients_Tab where client_id= ?";
//state = connect.createStatement();
ResultSet result = state.executeQuery();
while(result.next())
{

id = result.getString(1);
pref = result.getString(2);
//list= result.getString(3);
fpath = result.getString(3);

System.out.println("path picked"+" "+fpath);

}
id=id.trim();
pref=pref.trim();

if(pref.equals("fixed") && list.equals("upload"))
{
s = new Socket("crux",1024);
System.out.println("CONNECTED To CLIENT");
ss = new ServerSocket(1024);
s = ss.accept();
FileInputStream in = new FileInputStream(fpath);
BufferedOutputStream bout=new BufferedOutputStream(s.getOutputStream());
int k;
System.out.println("SENDING...");
while((k=in.read())!=-1)
bout.write(k);
bout.flush();
bout.close();
System.out.println("FILE SENT");

BufferedInputStream fin = new BufferedInputStream(s.getInputStream());
FileOutputStream out=new FileOutputStream("c:\\roy\\java1.txt");
int k1;


while((k1=in.read())!=-1)
out.write(k1);
out.flush();
out.close();
System.out.println("FILE RECEIVED");
validate=true;
}
else
{
validate=false;
System.out.println("sorry");
}
}

catch (Exception e)
{
System.out.println("ERROR SENDING sorry " + e);
// System.out.println("ERROR SENDING:"+e1);
}
/* catch(Exception e1)
{
System.out.println("ERROR SENDING:"+e1);
} */

return validate;
}

}

I get this error
Aug 23, 2005 6:53:36 PM org.apache.commons.modeler.Registry loadRegistry
INFO: Loading registry information
Aug 23, 2005 6:53:36 PM org.apache.commons.modeler.Registry getRegistry
INFO: Creating new Registry instance
Aug 23, 2005 6:53:37 PM org.apache.commons.modeler.Registry getServer
INFO: Creating MBeanServer
Aug 23, 2005 6:53:38 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on port 8080
Starting service Tomcat-Standalone
Apache Tomcat/4.1.12-LE-jdk14
Aug 23, 2005 6:54:00 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on port 8080
Aug 23, 2005 6:54:01 PM org.apache.jk.common.ChannelSocket init
INFO: JK2: ajp13 listening on tcp port 8009
Aug 23, 2005 6:54:01 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=16/391 config=C:\Program Files\Apache Group\Tomcat 4
.1\conf\jk2.properties
path picked c:\roberts\java1.txt
ERROR SENDING sorry java.net.ConnectException: Connection refused: connect

guess I am stock any suggestions I would be very glad and if my whole approach is wrong pls tell me what thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: connecting and copying files in tomcat
 
Similar Threads
Some help required for understanding spring lifecycle
NullPointer Exception When calling RequestDispatcher
java.lang.NullPointerException
Cannot start Tomcat as a service
"Application has unexpectedly stopped error" when adding onClickListener