Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: JAVA applet URL path (My computer and Web Host)

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JAVA applet URL path (My computer and Web Host)

    So I have a problem with loading the exact json_GetTownInfo.php file on Web Host where applet located. On my computer where I code the project i wrote URL myhost.com/jquery/json_GetTownInfo.php and it successfully loads it testing. When I change the URL to ../jquery/json_GetTownInfo.php and put my compiled dara.jar to Web Host it won't load at all nor myhost.com/jquery/json_GetTownInfo.php as a string in URL object...
    So please help me to determine how to properly use URL's in java to load it on Web Host...?

    where myhost.com - should be with http, because forums denies post...

    My located JAVA files are here: myhost.com/java , java.html(Where to show applet) and main dara.jar(Applet file). JSON(PHP) is located here: myhost.com/jquery , json_GetTownInfo.php.

    java.html :
    <applet code="ArcanumUniverse.class" archive="dara.jar" width="800" height="600"/>

    json_GetTownInfo.php :
    <?php
        include "../style.class.php";
     
        $style = new style;
     
        $get_places = $style->get_town_info("place_ID,place_Name,place_MapX,place_MapY,place_ImageMap", 1);
     
        echo json_encode($get_places);
    ?>

    ArcanumUniverse.java(compiled in dara.jar) :
    URL url;
            JsonReader reader = null;
            try {
                url = new URL("../jquery/json_GetTownInfo.php");
                try {
                    reader = new JsonReader(new InputStreamReader(url.openStream()));
     
                    Type listType = new TypeToken<List<TownData>>() {}.getType();
                    List<TownData> data = new Gson().fromJson(reader, listType);
     
                    System.out.println(data.get(0).place_ID);
                    System.out.println(getCodeBase());
                    placee = data.get(0).place_ID;
     
                    //System.out.println(data.getTownIndex());
                    /*for (int i = 0; i < data.size(); i++)
                    {
                        data2.add(new TownData(data.get(i).place_ID));
                    }*/
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (MalformedURLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Basic misunderstanding of how applets work (happens to most of us in the beginning).

    Java Applets run on the client-side, NOT the server side. In your client application, a URL like this: "../jquery/json_GetTownInfo.php" would look for a file located in the user's local file system, not the online server.

    For example, if you attempted to access a database using localhost on a Java applet, it would attempt to locate the database on the client's machine, not the server. In comparison, php is a server-side language, so attempting to access a database using localhost in php code WOULD refer to a database on the server.

    An applet is embedded in the user's local browser, NOT the server, so relative paths to server resources is impossible. You need to do a direct link, eg: "yourdomain.com/jquery/json_GetTownInfo.php"
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    I understood, but "http://mydomain.com/jquery/json_GetTownInfo.php" still not working, it works only from where I launch Applet and it is from my Eclipse project folder, where all code goes, but when I put that compiled .jar file to web host same "http://mydomain.com/jquery/json_GetTownInfo.php" won't work.

  4. #4
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Are you getting any exceptions thrown? Make sure you have the java console open when you run the applet if you want to see any console logging/printing.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Thats why I posted, there is no exceptions it just won't run exactly from the web host... dunno why... But I've added debugging(just printing messages) and it seems that something wrong with this (reader = new JsonReader(new InputStreamReader(url.openStream()));) thats the LAST station

    EDIT: Ohh god find my mistake I need to use default .jar export, not Runnable, but still I need to include GSON library to my project to run that code above? How to include external library in Eclipse for exporting? That thing too confusing me (Eclipse won't include it in project on not runnable export of .jar)

  6. #6
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Probably a silly question on my behalf, but just to check: is JsonReader part of the normal java api, or is it an external library/plug-in (I'm not familiar with that particular class)? And, on that note: are you using any external libraries or plug-ins? I ask because while Eclipse will handle that happily, if you deploy your program without those external libraries, java has no way of knowing where or how to get them, which will result in all sorts of runtime errors (missing classes and such).
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  7. #7
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    ^ I've edited post above yours, before you wrote ^

  8. #8
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    This is where we might need a second opinion. I handle dependencies with Maven, but I don't suggest recreating all of your projects just for this purpose (it is one of those things that you want to set up before you start working on your project, not when you are ready to deploy).
    I understand the best alternative is an ant script, but I don't know how to do that.
    There is also a tool named Fat Jar (Fat Jar Eclipse Plug-In) which may do it, but I have no idea how it works.

    I know that in an executable jar, you can specify the external libraries in the manifest, but I do not know if that works for non-runnable jars. I've managed to solve this problem this way with Applications, but I don't think I've ever even had to try this with Applets (best guess is that it won't work).

    I'm not sure how useful I am for this problem.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  9. #9
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    I've tried with class-path manifest, no luck. Thanks for trying to help, maybe I'll try Fat Jar, but still this thread is open for opinions,suggestions. I will wait

  10. #10
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Tried with FatJar + class-path, gosh same result, stops on JsonReader... I think FatJar is the same Runnable Jar

  11. #11
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    Okay, it seems that GSON works on my web page, but the real problem with GSON syntax... Don't know what really happens, so I have now this code:
    url = new URL("http://h-lodge.lt/jquery/json_GetTownInfo.php");
    reader = new JsonReader(new InputStreamReader(url.openStream()));
     
    Type listType = new TypeToken<List<TownData>>() {}.getType();
    List<TownData> data = new Gson().fromJson(reader, listType);
    The problem is between reader and fromJson function, I've tried to do: int data = new Gson().fromJson("1", int.class) and it works fine, prints me value, so any suggestions how to fix that communication between JsonReader/BufferedReader and fromJson...? I've tried to fix hundred times till now, no success...

    P.S. reader successfully gets the data.

  12. #12
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    What sort of error or problem are you getting?
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  13. #13
    Junior Member
    Join Date
    May 2013
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JAVA applet URL path (My computer and Web Host)

    No errors at all
    EDIT: God damn that sh... I've tried billion methods, nothing works, even red this: http://code.google.com/p/google-gson...nsExample.java
    However, deserialization with fromJson(json, Collection.class) will not work since Gson has no way of knowing how to map the input to the types.
    Option 1: Use Gson's parser API (low-level streaming parser or the DOM parser JsonParser) to parse the array elements and then use Gson.fromJson() on each of the array elements.This is the preferred approach. Here is an example that demonstrates how to do this.
    Tried the last method, the last chance, still fromJSON won't work, won't use STRING or READER, program just stucks... no errors no nothing. Works only on ECLIPSE IDE running application, on web no luck...

Similar Threads

  1. Best web host for Java EE
    By laresistance2 in forum JavaServer Pages: JSP & JSTL
    Replies: 9
    Last Post: August 13th, 2012, 04:18 PM
  2. Free Web Host That Allows Java
    By aussiemcgr in forum Java Theory & Questions
    Replies: 3
    Last Post: August 26th, 2011, 11:05 AM
  3. Seeking host for Google Web Toolkit
    By laresistance2 in forum Web Frameworks
    Replies: 1
    Last Post: June 9th, 2011, 04:29 AM
  4. java applet program question (on getting path fails)
    By hellocheese in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 30th, 2011, 04:34 PM
  5. Making computer independent file path
    By Javabeginner in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: September 2nd, 2010, 03:56 PM

Tags for this Thread