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
    Posts
    1

    Communication between Java and HTML

    Hello,

    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.

    Thanks.

    Cyril

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    the only way i can think of is to use a servlet. have the java class defined something like this
    Code:
    public class SomeClass extends HttpServlet
    {
        public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
    	{
            String pageName req.getParameter("pageName);
     
            //writeToTheFile(pageName);
        }
    }
    and the html code for the button would be
    Code:
    <form action = 'SomeClass' method = 'post'>
    <input type = 'hidden' name = pageNumber value = whateverYouWant> //this will be an invisible parameter
    <input type = 'submit' value = 'press me'>
    </form>
    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
    Posts
    20
    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
    Posts
    808
    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...

    see:

    http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequest.html#getRequestURI()


    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, www.dictionary.com 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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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