• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

connecting and copying files in tomcat

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic