Opening a text file in server from an applet running in the client

Friends,
I want to open a text file in the server(The server machine uses tomcat 4.1.12 server)from an applet running in the client machine;
The applet invokes a servlet that opens the text file;this text file is opened in the server machine; but I want it to be opened in the client machine where the applet is running.
Plese help me to get around this.

You can open the textfile on the servlet and then send the information to the client (applet) as stirngs. The must then applet convert the stirngs into some object or simply display the information in someway. But then the text file that you are opening must be stored in some relevant tomcat directory e.g. on the server. If you want to open a file on the clients computer, you get into signed applets.

Similar Messages

  • Create a new file on server from an applet

    Hello!
    I 'm trying to create a text file on server from an applet, i have permissions to write on server and i'm running in apache, my code is
    public void write () {
    try{
    URL url = new URL("http://localhost/bnm/hello.txt");
    URLConnection urlcon = url.openConnection();
    urlcon.setDoOutput(true);
    urlcon.setUseCaches(true);
    PrintWriter pt = new PrintWriter
    (new OutputStreamWriter (urlcon.getOutputStream()));
    String str = new String(URLEncoder.encode("this is output applet ")) ;
    pt.print(str);
    pt.flush();
    catch(Exception e)
    e.printStackTrace();
    The result is nothing, the file isn�t created, but the code don't throw exceptions.
    Ah! in other example, i can read a file of server fro m the applet, the problem is to write
    Anybody, knows the matter??
    Excuse my poor english :P
    Thanks for all.

    I had the same needs and didn't know whether this was possible, due to applets security restriction. So I searched the Web and found some contradictory information. I will explain what I think is the situation, to give you an answer, but also so that other people can tell me whether I understood correctly.
    1) Unless you sign it, an applet cannot write files directly, either client-side or server-side. All what it can do to access a file server-side (except .jar files ?) is opening a http connection, which allows only to retrieve data. When I try to run code such as yours, I get this exception :
    java.net.UnknownServiceException: protocol doesn't support output
         at java.net.URLConnection.getOutputStream(URLConnection.java:679)
    2) As Ares_Man points out, what it can do is opening a http connection not directly with the file you want, but with a server-side script (JSP, PHP, CGI,...) which will be allowed to write files on the server. You can use POST or GET parameters to pass to the script what you are going to write.
    This simple code worked for me (it executed the script toto.php):
              try{
                   URL toto=new URL(getCodeBase(),"toto.php");
                   InputStream f=toto.openStream();
                   f.close();
              catch(Exception e){
                   e.printStackTrace();
    Probably it's a good idea to do a URLConnection.setCache(false) though, to be sure that the script toto.php will be executed.
    3) I don't know how you can pass serialized objects as parameters. So if more than text informations are to be written, I would tend to make the script store them into a database instead of files. That way, you could pass any SQL query as parameter, maybe along with a password parameter for security. I don't know whether this is secure enough.

  • When I attempt to open a PDF file I saved from a website, I get the message "There was an error opening this document. The file is damaged and could not be repaired." Is there any way to correct this problem?

    When I attempt to open a PDF file I saved from a website using Safari, I get the message "There was an error opening this document. The file is damaged and could not be repaired." When I save the same PDF file using FireFox it opens up immediately. Is there any way to correct this problem with Safari?

    Back up all data.
    Triple-click the line of text below to select it, the copy the selected text to the Clipboard (command-C):
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, remove any items that have the letters “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari, and test.
    The "Silverlight" web plugin distributed by Microsoft can also interfere with PDF display in Safari, so you may need to remove it as well, if it's present.
    If you still have the issue, repeat with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari again.

  • How to open a text-file with notepad from labview-vi?

    Hello,
    how can i execute a program from a vi?
    I want to open a textfile with Windows7-Notepad after selelecting it from a file-path-control and pressing an open-button.
    Thx for help
    Solved!
    Go to Solution.

    Use the command line.  Something like cmd /c notepad c:\temp\blah.txt should work.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How do I open a text file to sort using bubble sort?

    Hi,
    I have a text file, which is a list of #'s.. ex)
    0.001121
    0.313313
    0.001334
    how do you open a text file and read a list? I have the bubble sort code which sorts.. thanks

    I wrote this, but am getting a couple errors:
    import java.util.*;
    import java.io.*;
    public class sort
         public static void main(String[] args)
              String fileName = "numsRandom1024.txt";
              Scanner fromFile = null;
              int index = 0;
              double[] a = new double[1024];Don't use double. You should use something that implements Comparable, like java.lang.Double.
              try
                   fromFile = new Scanner(new File(fileName));
              catch (FileNotFoundException e)
    System.out.println("Error opening the file " +
    " + fileName);
                   System.exit(0);
              while (fromFile.hasNextLine())
                   String line = fromFile.nextLine();
                   a[index] = Double.parseDouble(line);Don't parse to a double, create a java.lang.Double instead.
                   System.out.println(a[index]);
                   index++;
              fromFile.close();
              bubbleSort( a, 0, a.length-1 );No. Don't use a.length-1: from index to a.length-1 all values will be null (if you use Double's). Call it like this:bubbleSort(a, 0, index);
    public static <T extends Comparable<? super T>> void
    d bubbleSort( T[] a, int first, int last )
              for(int counter = 0 ; counter < 1024 ; counter++)
    for(int counter2 = 1 ; counter2 < (1024-counter) ;
    ) ; counter2++)Don't let those counter loop to 1024. The max should be last .
                        if(a[counter2-1] > a[counter2])No. Use the compareTo(...) method:if(a[counter2-1].compareTo(a[counter2]) > 0) {
                             double temp = a[counter2];No, your array contains Comparable's of type T, use that type then:T temp = a[counter2];
    // ...Good luck.

  • SSO Issues while opening a ppt file document only from Solution Manager

    Hi Experts,
    Version - Solman 3.1
    Issue
    =====
    While trying to open a Powerpoint(ppt) file document, from the service provided by Solution Manager thru a weblink:
    1.A SSO authentication request of the server pops up requesting to authenticate Windows userid/password
    2.After entering the windows password the first time..authentication is requested again..At times on the second chance of authentication, the request is successfull and the powerpoint document opens.. But we have faced issues wherein the issues had persisted for 5-6 chances and only then the ppt document opens.
    3.Point to be noted is that even if the SSO authentication of the windows password is cancelled even the first chance the document opens..
    4.Issue is only with powerpoint document and not with word document..
    Going by point 3.. there is no relevance of the windows authentication to popup since authenticating or not authenticating doesn't matter.
    Issue unknown is why is that whenever only a ppt document from Solman is being opened does the SSO Windows authentication window of Solman server opens.. Is there any settings to be considered..
    Regards,
    Nagendran

    Since I am new to the field requesting the kind quick help by java experts here to help me change the code so that I would be able to search a web apge saved on disk and search and highlight a word in that page ....
    Thanks in advance........
    Looking forward for your kind suggestions......1) Did you write that code? If yes, proceed to 2). If no, I charge 150 euros/hr. Let me know when you want me to start.
    2) Post the code for a program that opens a text file with the following in it:
    hello world
    and prints the contents out using System.out.println().
    3) Modify the program in 2) to determine if the file contains the word "yes". Post the code.
    4) An html file is no different than the text file in 2).

  • Recommended way to open a text file included in a jar?

    Forgive me if this seems like an ignorant question, but I keep reading two different things about loading resources in the javadocs and forums, and can't seem to connect them...
    Say you want to open a text file and read the contents into a String or a List. Apparently, the preferred way to do this is something like:
    fileName = "myFile.txt";
    BufferedReader br = new BufferedReader(new FileReader(new File(fileName)));
    String line;
    while ((line = reader.readLine()) != null) {...}
    Now say you want to distribute your app in a jar file, with the text file included in the jar file. The above method won't work, because a FileReader operates on a File, and as I understand it, once myFile.txt is packed into the jar file, it's no longer a "file".
    So what do you do? I keep reading that the best way to open the jarred text file is to use something like this:
    InputStream is = getClass().getResourceAsStream(fileName);
    Here's where I get confused: InputStream, and all of its subclasses, are now supposedly dispreferred for reading character data (in preference to Reader, as above). But no subclass of Reader can wrap around an InputStream, which would facilitate the reading of character data greatly, with methods like readLine().
    So my question is: What's the best way to read a text file from within a .jar?
    Thanks,
    Gregory

    great! glad it's working
    here is a statement from the javadoc
    http://java.sun.com/j2se/1.4.2/docs/api/java/io/InputStreamReader.html
    For top efficiency, consider wrapping an InputStreamReader within a BufferedReader. For example:
    BufferedReader in
    = new BufferedReader(new InputStreamReader(System.in));
    kind regards
    Waken16

  • Opening a text file in a bundle with C++

    Hi folks! I'm working with bundles for the first time, and I'd like to know how to open a text file inside one with C++. What I have now is this:
    ifstream file = new ifstream(fileName.c_str());
    if (!file->is_open())
    return false;
    Where fileName is a std::string. This is the way I'm accustomed to opening files (I'm from a Windows development background -- don't hate me! ). Unfortunately, the is_open() test always fails.
    I know how to get the path of the bundle. Once I add on my data subdirectory and file name, the fileName variable ends up as this:
    /Users/sb/...project location.../Debug/MyProg.app/data/Dev Options.ini
    Should the path be different somehow? Thanks for any help!

    Your data folder most likely isn't directly inside the .app bundle. The first directory inside an .app bundle is named Contents. The article at the following URL should help you:
    http://www.meandmark.com/bundlespart1.html
    If you're going to use C++ streams to open files, you'll want to ignore the section on opening the file in Part 3 of the article. You'll want to read up on the Core Foundation CFURL functions. You'll want to use one of the functions that gives you a path to the text file that you can pass to a C++ file stream.

  • I recently updated my OS to OS X. I had to update my word and powerpoint etc... to 2011 version, but now when I want to open a .doc file made in word 2003 it removes all the text in it! I did not back anything up!

    I recently updated my OS to OS X. I had to update my word and powerpoint etc... to 2011 version, but now when I want to open a .doc file made in word 2003 it removes all the text in it! I did not back anything up! All my mums work is on there for her job and now she cant use it! I need help fast!

    If you updated from 2003 that must be on a Windows machine, can you recover them from there?

  • Can Quickword open a text file 10K?

    I have a couple of simple, notepad text files.
    6K opens (after about 5 seconds)
    90K, well, it doesn't
    480K, neither does this.
    I can open the files using notepad, direct from the phone.
    Can anyone else open simple text files of this range of size.
    ...Lyall

    Well, I have a Tab Separated variable file (output from Excel) with about 20 columns.
    I edited it down from 5000 lines to 1000, 500 and 250 lines.
    I then copied all 4 files to the E90.
    QuickWord will open the 250 line file after about 5-10 seconds.
    It does NOT open (at least within my lifetime) the 500+ line files.
    So, how do I look at text files on the E90?
    ...Lyall

  • Creation of files on server from client

    i want to create a file on server from client.
    so i have to create the file using uri that resides on server, but i am not able to create file using that URI
    i want to create in this location.
    "http://localhost:8080/web/a.jsp"
    so please give me the syntax for that.
    thanks in advance

    i checked that url........but its talking ablut urlconnection and url......but i want to create file with uri....could u plz help me
    thx & regds

  • Cannot acess file on server from client machine using java web start

    Hi everyone,
    I am creating an appication using JWS and Apache Web Server version 2.0.54 on Linux. I am trying to access a file on the server that IS NOT inside the jar file. I have given full access (r, w, x) to all users on my server. We also created a FilePermission object and gave the file read and write access as well. But when we deploy the program and try to get this file, a SecurityException is thrown with the following mesage:
    acess denied (java.io.FilePermission filename read) where filename is the file in our local filesystem. Any suggestions on what I can do?
    Any help would be greatly appreciated.
    Thanks,
    Raj

    It sounds like you are trying to access the file as if your JNLP application were running on the server. The JNLP app is running on the client machine, so you will need to use a URL to open the file. Take a look at the JavaDocs for the following:
         java.net.URL
         java.net.URI
         java.net.File
    You also need to be sure your server is configured to serve the file. For example, you ought to be able to access the file through your browser using something like http://www.myco.com/myapp/myfile.txt. (How you configure your server is a topic for a different forum.)
    You probably also want to look into JavaWS security, and even Java security in general to determine if you need to sign your app or not. Here are some links to get you started:
            http://java.sun.com/j2se/1.5.0/docs/guide/javaws/developersguide/development.html#security
            http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/security.html
            http://java.sun.com/sfaq/
            http://java.sun.com/j2se/1.5.0/docs/guide/security/permissions.html
            http://java.sun.com/j2se/1.5.0/docs/guide/security/index.html
    Mike.

  • Opening a Text File?

    I am having no luck opening a text file that contains comma delimited data. I have tried some different ways and am having no luck at all. I can't even get a open file dialog to appear when I click a button.
    I did not see any example of this in the sdk sample plugins.
    Anyone able to help me out.
    The file I am trying to load is "D:\Test\TestFile.txt".

    If you did not escape the path's backslashes that may be part of the problem.
    Some example code:
    local LrDialogs = import 'LrDialogs'
    local LrFileUtils = import 'LrFileUtils'
    local LrPathUtils = import 'LrPathUtils'
    local file = 'C:\\temp\\Testfile1.txt'
    if not LrFileUtils.isReadable(file) then
    local dialogresult = LrDialogs.runOpenPanel {
      title = 'Select input text file',
      allowsMultipleSelection = false,
      initialDirectory = LrPathUtils.parent(file)
    file = dialogresult and dialogresult[1] or nil
    end
    if file and LrFileUtils.isReadable(file) then
    local collectedLines = {}
    for line in io.lines(file) do table.insert(collectedLines, line) end
    LrDialogs.message(table.concat(collectedLines, '\n'))
    end
    Herb

  • How to open a text file using button click event

    hi, How can i open a text file in a textpad or notepad on the click event of a button.?
    Thanks
    Jay

    Pnt,
    this will not work LV 8.0.1 and LV 8.6 will give back error 193.
    Attached is a VI to use the ShellExecute WinAPI. The VI is LV 7.1.1.
    Message Edited by waldemar.hersacher on 10-09-2008 10:48 PM
    Waldemar
    Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
    Don't forget to give Kudos to good answers and/or questions
    Attachments:
    ShellExecute.zip ‏27 KB

  • Write to file on server from app

    Am trying to write to a file on server from an application like this:
    java.net.URL url = new java.net.URL("http://www.rikif.dk/test.txt");
    URLConnection conn = url.openConnection();
    conn.setUseCaches(false);
    conn.setDoOutput(true);
    PrintStream out =
    new PrintStream(conn.getOutputStream());
    out.print("sdfsdf");
    out.flush();
    out.close();
    But nothing happens. What am I doing wrong?

    No exceptions.. "Unlike other output streams, a PrintStream never throws an IOException".
    You can write a file through HTTP into a web server? It does not make sense really.. is the file writable in the web server?
    And why be writable - anyone would be able to write it then.
    You can achieve that through sockets. A java program on the remote machine (playing the role of a server) would accept data through a socket from the clients, and would write the files itself.. without need of web servers.
    You can use a tomcat server, and use a servlet, again to accept data and write the files itself.
    ..or?

Maybe you are looking for

  • How to delete music from an external hard drive

    Hi I have 1 Toshiba and 1 WD Elements external hard drive which is working find the only problem I have is  that I can not transfer files music videos nothing between this 2 external Hard Drive's and I can not Delete  anything while they are connecte

  • How do I open an old psd. file?

    I'm trying to open a 10 year old psd. file with Photoshop CS2 and it tells me it is not a Photoshop file. What can I do to open it???

  • Asset master conversion

    Hi,   If trying to migrate assets is it possible to create the asset and load balances in one pass through LSMW. We have tried this but the application complains about the presence of a 'B' record type in the data from LSMW, which appears to be a def

  • Calling a method in the Custom ADF component from JSF page

    HI. I have created some custom compoents by extending the core ADF Components. Like i have a ComboBoxDefault component with it's ComboBoxDefaultTag.java and Controls.tld file. Now my requirement is i want to bind my label to this component from the J

  • Total Area Coverage below 200?

    Is there anyway to change the total area coverage to be below 200% in the output preview window? We recently changed newspaper stock and I need to be able to see ink density warnings for 165% or higher. 200% seems to be all that Acrobat allows- Any w