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.
the only way i can think of is to use a servlet. have the java class defined something like this
and the html code for the button would be
public class SomeClass extends HttpServlet
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
String pageName req.getParameter("pageName);
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.
<form action = 'SomeClass' method = 'post'>
<input type = 'hidden' name = pageNumber value = whateverYouWant> //this will be an invisible parameter
<input type = 'submit' value = 'press me'>
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.
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?
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
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center