|
For as far as I know webservers will not allow you to do this, at least not the way you want by opening or creating a file remotely and writing to it.
What you could do is write some servlet or JSP code on the remote server that accepts POST data and writes that to a file. You can then POST any content to that JSP / Servlet and store data that way.
EG:
server A has a servlet called /StoreFile
server B calls http://serverA/StoreFile
with POST data
fileName=file1.txt&data=<yourencodeddata>
|
|
|
|
|
Hello Gerban
THanks for ur reply but I am reading the file from server in same way.Thats why I thought that writing is also possible in the same way.
And i got this solution from net.
Anyway,I will try ur way also but still If u know any other way then please let me know.
Thanks Again for ur replay.
Regards
Yogesh
|
|
|
|
|
Reading should never cause you any issues, as this is the primary reason to have a webserver (get access to remote files).
The real question is why would you want to have unprotected writing to a webserver at all (which you are doing if you open a file on a remote server and just start writing in it). You would create a serious security risk.
If it is at all possible to write directly to a webserver from a remote connection then that will be a security setting on the webserver, and not on the Java side of things. So maybe you should also ask this question on some forums relating to Tomcat / Apache or whatever webserver you are running.
|
|
|
|
|
Thanks For ur Reply.
Yeah,I understand this would be a security risk.So I have to drop this way.
Thanks
Regards
Yogesh
|
|
|
|
|
Hello Friends
I want to add progress bar moving while I am reading a file.
Any Ides Guys?
Thanks & Regards
Yogesh
|
|
|
|
|
The simplest option is simply to start a progress bar running in indeterminate mode (i.e. the bar just bounces back and forwards to show you that something is happening), then load the file, then stop the progress bar when you are finished loading. That way you never need to worry about how big the file is.
The alternative is to get the length of the file before you start (create a File object, and call length()) then track the number of bytes you have read in as a percentage of the total and update the progress bar periodically. Don't update the progress bar too often (e.g. if you have a 2Mb file and you update the progress bar after reading every individual byte, you will be updating the progress bar over 2 million times, which is obviously not a good idea). Make sure you don't load the file on the Swing event handling thread, but make sure that you do update the progress bar on the EDT.
Or, you could use a ProgressMonitor, which is an inbuilt progress dialog that is sometimes useful.
Progress bar tutorial here:
http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/progress.html[^]
|
|
|
|
|
Thanks A Lot.Mr David
Regards
Yogesh
|
|
|
|
|
Hello Friends
I am using file object to with URL path as parameter to pass filename to some function.But it is not creating File Object.I tried like this:
String filePath="http://test.com/folder/file.txt
File f = new File(new URL(filePath).toURI());
And like this too
File f = new File(new URL(filePath).getPath());
but it is crashing at this point.
Any Ideas Guys.
Thanks In Advance.
Regards
Yogesh
|
|
|
|
|
yogeshs wrote: but it is crashing at this point.
Any Ideas Guys.
Well perhaps if you showed the error that you received we may be able to help work out what is going wrong. However, I am not sure that you are allowed to create files on a client machine in this way.
It's time for a new signature.
|
|
|
|
|
Hello Sir
Actually I am facing some exception when I run and its java.lang.reflect.InvocationTargetException.
May be this one useful for you.I searched for this but didnt found anything.
Thanks & Regards
Yogesh
|
|
|
|
|
The explanation is here[^], also some discussion about what information it holds. You should catch this and then display its cause details to help identify what is going wrong.
It's time for a new signature.
|
|
|
|
|
Guys
I'm trying to applying singleton pattern to TCP server client application
But I get some run time exceptions.I tryed out diffrent ways.
Please give me your suggetions to correct this
here TCPServer is the Singleton
in my client(TCPClient) I want to access TCPServer but I can not do it.
TCPServer Class
import java.io.*;
import java.net.*;
class TCPServer {
private String capitalizedSentence;
private ServerSocket welcomeSocket;
private String clientSentence = new String(" d");
private BufferedReader inFromClient;
private DataOutputStream outToClient;
private Socket connectionSocket;
private static TCPServer instance = null;
private TCPServer() throws Exception {
}
private TCPServer(int socketID) throws Exception {
if( welcomeSocket==null){
}
}
public static TCPServer getInstance() throws Exception {
if(instance == null) {
instance = new TCPServer();
System.out.println("This is new server instance created");
}
else if(instance !=null){
System.out.println("This is old instance");
}
return instance;
}
public void method()
{
System.out.println("This is server");
}
public void run() throws Exception{
welcomeSocket = new ServerSocket(6789);
while(clientSentence.equals("exit")!=true) {
connectionSocket = welcomeSocket.accept();
inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
outToClient = new DataOutputStream(connectionSocket.getOutputStream());
clientSentence = inFromClient.readLine();
System.out.println("Recived from client : " + clientSentence);
capitalizedSentence = clientSentence.toUpperCase() + '\n';
outToClient.writeBytes(capitalizedSentence);
}
}
}
TCP Client Class
import java.io.*;
import java.net.*;
class TCPClient {
private String sentence,modifiedSentence;
private DataOutputStream outToServer;
private BufferedReader inFromServer;
private Socket clientSocket;
private BufferedReader inFromUser;
public TCPClient() throws Exception{
inFromUser = new BufferedReader(new InputStreamReader(System.in));
clientSocket = new Socket("192.168.1.2", 6789);
outToServer = new DataOutputStream(clientSocket.getOutputStream());
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
public String getSentence()
{
return sentence;
}
public void setSentence(String str)
{
this.sentence=str;
}
public String getModifiedSentence()
{
return modifiedSentence;
}
public void setModifiedSentence(String str )
{
this.modifiedSentence=str;
}
public void run() throws Exception{
System.out.println("Enter a String");
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + '\n');
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
TCPServer mySever = TCPServer.getInstance();
clientSocket.close();
}
}
Calling class
To Server
public class Server{
public static void main(String[] args) throws Exception{
TCPServer x = TCPServer.getInstance();
x.run();
}
}
To client
public class Client{
public static void main(String[] args) throws Exception{
TCPClient client = new TCPClient();
client.run();
}
}
|
|
|
|
|
Nadunwow wrote: But I get some run time exceptions.
Well it's not easy for us to guess what those may be. Please explain exactly what exceptions you get, and where in the program (i.e. line of code) that they occur.
It's time for a new signature.
|
|
|
|
|
I fixed them
and Not code is updated.
Then I get another problem
I need only one instance of siglton(TCPServer).
But My client connect to one instance but How can I access that instance in TCP client ?
if I can not is it possible to pass the TCPClient as a object to TCPServer ?
What is the procedure I should follow ? Any idea ?
|
|
|
|
|
Sorry, but I'm not sure what you are asking.
It's time for a new signature.
|
|
|
|
|
I'm not sure he is either.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
There could be several answers depending on the /real/ question. Are you looking for:
A single server that many clients connect to?
A server that accepts one and only one connection?
A client that can only connect to the server once?
Just because you've read about the singleton, does not mean it is the right pattern here.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
I am just started playing with java an I am having this issue. I did the simple hello world app like this:
class HelloWorldApp {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
And when I run it in eclipse the console shows Hello World!, But if I run it in the terminal as "java Hello?WorldApp.class"
It will not run it just gives me the error "Class not found". Why is this? Thanks. Running Ubuntu 10.04.
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldApp/class
Caused by: java.lang.ClassNotFoundException: HelloWorldApp.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
Could not find the main class: HelloWorldApp.class. Program will exit."
Y*Live Long And Prosper*Y
|
|
|
|
|
Why did you add ".class" after the class name ? You should execute it like this: java HelloWorldApp
|
|
|
|
|
Ohhhh... I didn't know that. Thanks!
Y*Live Long And Prosper*Y
|
|
|
|
|
Hello Friends
I am reading a file that is one level down in directory from my source file.
Suppose if my source file is in c:\Test\source then file that I m reading is in c:\Test\test1\readFile.
If I provide full path then it is loading but if i provide relative path like test1/readfile then it is not laoding.
Is there some different way in java to load file from relative path?
Any Help will be Appreciated.
Thanks & Regards
Yogesh
|
|
|
|
|
I would guess that your code is in c:\Test\source , but where is the jar?
Secondly, when you run the jar, either from the command, double click or via the IDE, what is the runtime execution folder? That is where you should be reletive to, using .. to go up and . for the current folder.
Panic, Chaos, Destruction.
My work here is done.
or "Drink. Get drunk. Fall over." - P O'H
|
|
|
|
|
Hello Nagy
First,Thx for ur Reply.
My jar file is also in same source folder. And I am running it by double click the jar file that opens my application.After that i am loading file on some button click.
And Is there any difference If I use front Or backSlash while giving the relative path?
Thanks Once Again for ur Precious time to answer my question.
Regards
Yogesh
|
|
|
|
|
Hi guys
Actually This is an applet where I am loading a file.Now,when I run from some hard drive location with parameter '.\test1\readfile then Its working with this relative path and in firefox browser not in IE.
Now When I Load the same in localHost and then tried then it is not loading even in firefox with relative path.
Now,two question.why its not loading in IE with relative path?
Why its not loading when I run in LocalHost?
Any ideas Please?
Thanks & Regards
Yogesh
|
|
|
|
|
Hello Guys
The main problem is that i want to load resources through jar applet from System or when it is host?
ANy Ideas Now?
Regards
Yogesh
|
|
|
|