0

Is it possible to embed html with java

test.html

   <input id="buttonId" type="button" class="button-click"
    value="" onClick="checkSucess(2)" onload="counts(count)">

test.js

 checkSucess = function(firstVal) {

    // Jquery Ajax with url,params and response
      doPost('test.java',
        'first=' + firstVal,
       function(response) {

       });

test.java

Here get the 'first' value from ajax request, and further processing.
6
  • 2
    Huh? What exactly do you mean? Commented Jan 27, 2012 at 18:17
  • @BrianRoach : I want to know whether pure html code be used with Java, not applet/Swing etc. Commented Jan 27, 2012 at 18:19
  • 1
    Java has a string type, right? Then the answer is "yes". But that's not a meaningful answer, because you haven't asked a meaningful question, really. What are you trying to do? Commented Jan 27, 2012 at 18:22
  • @all: I am basically a PHP developer, doing my first assign in java. So I go in control flow from Html to javascript then to java Commented Jan 27, 2012 at 18:23
  • 1
    @Jusnit - Again, not sure what you mean by "pure html code" here. You seem to be wanting to do an AJAX request to something written in Java. You would need to write a Java servlet to handle that (running in a container such as Tomcat). Commented Jan 27, 2012 at 18:23

6 Answers 6

3

I believe you're looking for JavaServer Pages (.jsp), a starting point for implementing server-side logic using Java. (You can GET/POST to a jsp.)

Reference

Sign up to request clarification or add additional context in comments.

Comments

2

Well, Java on the server side doesn't work quite like PHP. i.e. you can't simply drop your java files in your htdocs directory and trigger it by filename directly. Firstly you'll need an app server like tomcat or jetty (instead of just a webserver like apache httpd). Secondly, you'll need to create a Servlet (simplest case) and write your java code there and trigger it using the server request url. Google "servlets" and you should be able to pick it from there..

Comments

0

No, you can't do like that, you have to use AJAX request to interact with java from your html or javascript. For that you have to use servlet and pass the servlet URL to doPost function.

doPost('url to servlet',
        'first=' + firstVal,
       function(response) {

       });

Comments

0

Since this is your first java project, you should do some reading to come up to speed with java. Here are some good tutorials:

Core Servlets, Intermediate Servlets

Apache Tomcat 6 - Apache is a nice tool for learning servlets; it is easy to install and run.

Core Servlets; Advanced Servlets - This may be more than you need.

Comments

0

Applets are Java, and the only (usual) way for Java in the browser.

You can communicate with Applets from Javascript/JQuery code. Applets have ending .class (.java is source code, you can't communicate with it).

In the case you want to communicate with serverside Java, you need servlets there. Then send requests to the url of the servlets.

1 Comment

Of course there are other ways to run Java on the client side, but applets will let you embed Java in a web page.
0

No. Besides using Java Applets - which are actually just plugins - there is no way to embed Java into HTML.

That being said, It is possible to generate HTML using Java Server Pages.

It is also possible to use an HTML page in conjunction with JavaScript to interact with Java via subsequent HTTP Requests made using AJAX. These requests are initiated on the client browser, and received and fulfilled by a server capable of executing Java Server Pages (JPS).

Example:

  1. An HTML page is loadad with some JavaScript that requests some url upon completion of DOM loading.
  2. The request is received by some server which then responds to the request.
  3. The client browser receives the response and provides it to JavaScript to be dealt with.
  4. JavaScript reads the response, and uses it in some way (like "refreshing" some information on the page).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.