Communication between Java and HTML

DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Communication between Java and HTML

  1. #1
    Join Date
    Mar 2004

    Communication between Java and HTML


    I would like to call a java class into my html page. The java class will use the name of the calling HTML page to write its name into a file.
    In fact I would like to write some informations (into a file on the hard drive) from the HTML pages that call the java class.

    Let's have an example :

    1- Click on a button in "page1.html" -> call of "java.class" -> "c:\file.txt" containts the string "page1.html"

    2- Click on a button in "page2.html" -> call of "java.class" -> "c:\file.txt" containts the string "page1.html,page2.html"

    3- Click on a button in "page3.html" -> call of "java.class" -> "c:\file.txt" containts the string "page1.html,page2.html,page3.html"

    and so on......

    I need to know the instructions to call and use the java.class into the HTML page.
    And I need to know the java instructions to get the HTML page name.
    Do I have to pass a parameter (name of the page) to the java class? If so how do I manage that on both side (java, HTML)

    I would like to have a universal code that works for Netscape / IE.

    Any answer will be grandly appreciated.



  2. #2
    Join Date
    Feb 2004
    the only way i can think of is to use a servlet. have the java class defined something like this
    public class SomeClass extends HttpServlet
        public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
            String pageName req.getParameter("pageName);
    and the html code for the button would be
    <form action = 'SomeClass' method = 'post'>
    <input type = 'hidden' name = pageNumber value = whateverYouWant> //this will be an invisible parameter
    <input type = 'submit' value = 'press me'>
    I assume you can do the same thing with java server pages but i've never used them so I don't know for sure.

    the html code for the button works for IE but i don't have netscape so i'm not sure if it's the same in that.

  3. #3
    Join Date
    Jan 2004
    Hey kenshiro06,

    Don't you just want to use an Applet?

    It just sounds like you just need to design an
    Applet to do everything you've described.

    Have you done an Applet before?

    Cheers, DJDaveMark

  4. #4
    Join Date
    Feb 2004
    applets are retarded, and have no access to the local filesystem. servlets are the better choice because, after all, every page must come from the server..

    but the proposed method in the servlet is maybe slightly wrong.. instead, you dont need to get any info from a form on the page, because the URL will contain the name of the document the user is trying to reach...


    for more info
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center