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 6 of 6

Thread: The best way to save data from a web server (JApplet class inserted in HTML file)

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Location
    Brasilia (Brasil)
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question The best way to save data from a web server (JApplet class inserted in HTML file)

    Although I am a high level programmer using C++ and Fortran for scientific programming, I am very new in Java.

    I have created a local host in my machine using APACHE2 in Windows 7. I intend to host a web site and I want to save data inserted by the user or data built from the dynamics of the users using the web site (I have a JApplet that does that).

    What is the best way to save data from the client side in the web server?

    I am trying to use "ObjectOutputStream toServer=new ObjectOutputStream(socket.getOutputStream());
    The idea is to include a Java class in a HTML file.

    Is this the best way to do that?

    Since this is the first time I am doing that, I am trying to use a source code of the book "Introduction to Java Programming - Liang" to test the concept. Although the JApplet works in the page, it is not able to save the file with the client information in my local host. It is worth stating that the codes of this book usually work very well. So I don't know if I am using the wrong concept or there is a problem between my JApplet and my web host server.

    I wonder if this is the best way to do that. Can anyone help me saying which is the problem I am facing?

    Is there any other easier way to do that? This is going to be a very simple web site with scientific purposes. Only students are going to access the site, therefore the only thing I need is to save the data provided by the students.

    Sorry if I am not clear or I am doing another kind of mistake, I am really very new in JAVA and also in this forum.

    Daniel


  2. #2
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: The best way to save data from a web server (JApplet class inserted in HTML file)

    Quote Originally Posted by danielCajueiro View Post
    Although I am a high level programmer using C++ and Fortran for scientific programming, I am very new in Java.

    I have created a local host in my machine using APACHE2 in Windows 7. I intend to host a web site and I want to save data inserted by the user or data built from the dynamics of the users using the web site (I have a JApplet that does that).

    What is the best way to save data from the client side in the web server?

    I am trying to use "ObjectOutputStream toServer=new ObjectOutputStream(socket.getOutputStream());
    The idea is to include a Java class in a HTML file.

    Is this the best way to do that?

    Since this is the first time I am doing that, I am trying to use a source code of the book "Introduction to Java Programming - Liang" to test the concept. Although the JApplet works in the page, it is not able to save the file with the client information in my local host. It is worth stating that the codes of this book usually work very well. So I don't know if I am using the wrong concept or there is a problem between my JApplet and my web host server.

    I wonder if this is the best way to do that. Can anyone help me saying which is the problem I am facing?

    Is there any other easier way to do that? This is going to be a very simple web site with scientific purposes. Only students are going to access the site, therefore the only thing I need is to save the data provided by the students.

    Sorry if I am not clear or I am doing another kind of mistake, I am really very new in JAVA and also in this forum.

    Daniel
    What's your webserver going to do with the data the students contribute? If it's only acting as somewhere to where the files must be sent, your simplest solution may be to sign your applet (so that it can write files locally) and ask your students to send you the output files by email. 'Web serving' for a lot of web servers is pretty much the same as 'file serving over HTTP'. Providing some functionality above and beyond file serving on the server can be a lot of work, particularly the first time you attempt it.

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Location
    Brasilia (Brasil)
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The best way to save data from a web server (JApplet class inserted in HTML file)

    Thank you very much for your answer.

    1) I am already running my Japplet as an application. When I do that I am able to save data using outDataAnswers = new PrintWriter(new FileWriter(dataAnswerName)); outDataAnswers.println(numberOfRightAnswers); However, to run this program I use java MyApplet in a window of DOS. I dont know if I am right, but I think I have to have jdk installed in my machine to do that. Unfortunately, I am not allowed to install it in a lab where the JApplet is going to be run. It is not very easy to put my application in each machine as well.

    2) The second issue is about safety. A student may eventually change the data and it would bring me concerns about the quality of the data.

    * About (1) Is it possible to run HTML page and save the data in the computer it is opening the HTML page without a server? And also without using the jdk software? If yes, which method should I use?

    ** Is there any place that you could guide me to find information about the entire process of saving data in a web host?

    Thank you again!

  4. #4
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: The best way to save data from a web server (JApplet class inserted in HTML file)

    You should only need the JRE, not the JDK, installed on client machines to run your applet. If you want to run the applet in a browser, you need the Java plugin installed correctly

    How do I test whether Java is working on my computer?

    Will tell you if you have the Java plugin installed in your browser.

    The reason why you can write files on your PC is because you're running your program as a local Java application, launched from the command line. Java Applets running in browsers are in a more secure environment called a 'sandbox' where some features (such as writing to the local filesystem) are denied. *Signed* applets can write to the local filesystem.

    If you really want to send the output of your applet to the webserver which originally served the applet to the client's browser, you can make a POST request using HttpUrlConnection to your webserver and send the data as the payload of that request. Note that there has to be something running on the webserver that can handle the request with the student's data in it. Whatever it is that responds to that request will have to be written by you in Java (Tomcat is a popular Servlet container) or another language like PHP. That code must understand the content of the request from your Applet and do something meaningful with it - probably save it in a database.

    The only other thing I can think of is for you to make a write-only fileshare available and ask the students to save the file the applet creates there. That's a workaround rather than a solution, but your project is only half complete - there's still a lot of work to do if you want the results from your applet to be captured in a cohesive way somewhere!

  5. The Following User Says Thank You to Sean4u For This Useful Post:

    danielCajueiro (March 1st, 2012)

  6. #5
    Junior Member
    Join Date
    Mar 2012
    Location
    Brasilia (Brasil)
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The best way to save data from a web server (JApplet class inserted in HTML file)

    Thank you again for the reply. I need some hours to absorb these pieces of information. Daniel

  7. #6
    Junior Member
    Join Date
    Mar 2012
    Location
    Brasilia (Brasil)
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: The best way to save data from a web server (JApplet class inserted in HTML file)

    (1) Is there any place that I can get a documentation with the necessary steps to do this? Maybe a book or a tutorial? I have got some information about individual steps in the internet, but I dont know how to put all the parts together!? (2) When you say that I should use Tomcat, are you suggesting that I should transform my JApplet in Servelet? Or I can also use the Tomcat for dealing with JApplets?

    "If you really want to send the output of your applet to the webserver which originally served the applet to the client's browser, you can make a POST request using HttpUrlConnection to your webserver and send the data as the payload of that request. Note that there has to be something running on the webserver that can handle the request with the student's data in it. Whatever it is that responds to that request will have to be written by you in Java (Tomcat is a popular Servlet container) or another language like PHP. That code must understand the content of the request from your Applet and do something meaningful with it - probably save it in a database."

    I hope that I am not bothering you with dummy questions, but it seems that I am a kind of lost. Thank you again!

Similar Threads

  1. trying to save data onto a file
    By DanTheSand in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: December 13th, 2011, 09:58 AM
  2. Help with Scanner class - Reading Data from a file
    By billias in forum What's Wrong With My Code?
    Replies: 7
    Last Post: June 28th, 2011, 01:07 PM
  3. [SOLVED] Get data from HTML file
    By zecute in forum What's Wrong With My Code?
    Replies: 0
    Last Post: May 8th, 2011, 10:12 AM
  4. Any way to write html form data to file?
    By nathan.fortier@gmail.com in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: January 14th, 2011, 03:03 PM
  5. Replies: 1
    Last Post: April 20th, 2009, 12:17 PM

Tags for this Thread