Basically you're asking something like: How to deploy a java applet for today's browsers (applet, embed, object)?

Based on that, I think what you want is:

<object 
  classid="clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA"
  style="height: 500px; width: 700px;">
  <param name="code" value="FinalProject.class">
    <comment>
      <embed code="FinalProject.class"
        type="application/x-java-applet"
        height="500" width="700">
        <noembed>
          This browser appears to lack support for Java Applets.
        </noembed>
      </embed>
    </comment>
  </object>

Now, you have a filename of main.FinalProject.class in your code. It seems like FinalProject.class would be more likely. But yours could be right. In any case, this html file needs to be in the same folder as main.FinalProject.class or FinalProject.class and whatever classes may also be required.

Now, you may also need to make sure your browsers can actually run an applet. See: How do I enable Java in my web browser?


Update

Based on feedback from Andrew Thompson, the preferred solution is to use JavaScript from Oracle, like this:

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {
        code:'FinalProject.class',
    width:700, height:500} ;
    var parameters = {}; // does the Applet take parameters?
    var version = '1.6' ; // does the Applet require a minimum version of Java
    deployJava.runApplet(attributes, parameters, version);
</script>

This requires the ability to load arbitrary JavaScript, but you could also capture that deployJava.js and have that be local as well. Might be worth a look.

Answer from artlung on Stack Overflow
🌐
Simple HTML Guide
simplehtmlguide.com › javaapplets.php
Java Applets in HTML - A Simple Guide to HTML
An applet is a Java program that can be included a web page by using HTML tags. The applet tag is the simpler but older method, and has been superseded by the object tag. ... Add a Java applet by specifying the attributes of the applet tag. archive="url" - Address or filename of the Java archive ...
🌐
HellGeeks
hellgeeks.com › home › how to use java code in html
How to Use Java Code in HTML - HellGeeks
September 23, 2024 - To deploy a JSP page, you have to place them inside a Java servlet container (web server). So, now, how do you deploy a Java web application? All you have to do is create a .war file with all your .jsp files and Java code. Then, you just proceed to compile. This is the simplest way to add Java code to HTML.
Discussions

Linking files to html and java script
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today. Start your free trial ... So we have learned that we can link more than one java script file to html, Can we link ... More on teamtreehouse.com
🌐 teamtreehouse.com
1
July 5, 2022
Best way to embed java code into an html file? - Stack Overflow
When you load the HTML in the browser the Java code has ended its execution and you cannot do any interaction with the Java side other than reload the same or other page entirely or using ajax requests. In any case, the Java code is executed in a server, not in the browser. ... Sign up to request clarification or add additional context in comments. ... You don't need to create a .jsp file ... More on stackoverflow.com
🌐 stackoverflow.com
html - How do I embed a java program into my website? - Stack Overflow
First off, this is for my web design class. I am doing a sort of "promotion website" for the game I made in my Computer Science 2 final for the final in this class. Everything is all good, except t... More on stackoverflow.com
🌐 stackoverflow.com
Run any Java in HTML pages with one line of <script>
This is amazing! Thanks for sharing. I see the code is at https://github.com/reportmill Is there an easy way to use this in my own site? More on reddit.com
🌐 r/java
37
101
September 5, 2025
Top answer
1 of 1
7

Basically you're asking something like: How to deploy a java applet for today's browsers (applet, embed, object)?

Based on that, I think what you want is:

<object 
  classid="clsid:CAFEEFAC-0015-0000-0000-ABCDEFFEDCBA"
  style="height: 500px; width: 700px;">
  <param name="code" value="FinalProject.class">
    <comment>
      <embed code="FinalProject.class"
        type="application/x-java-applet"
        height="500" width="700">
        <noembed>
          This browser appears to lack support for Java Applets.
        </noembed>
      </embed>
    </comment>
  </object>

Now, you have a filename of main.FinalProject.class in your code. It seems like FinalProject.class would be more likely. But yours could be right. In any case, this html file needs to be in the same folder as main.FinalProject.class or FinalProject.class and whatever classes may also be required.

Now, you may also need to make sure your browsers can actually run an applet. See: How do I enable Java in my web browser?


Update

Based on feedback from Andrew Thompson, the preferred solution is to use JavaScript from Oracle, like this:

<script src="http://www.java.com/js/deployJava.js"></script>
<script>
    var attributes = {
        code:'FinalProject.class',
    width:700, height:500} ;
    var parameters = {}; // does the Applet take parameters?
    var version = '1.6' ; // does the Applet require a minimum version of Java
    deployJava.runApplet(attributes, parameters, version);
</script>

This requires the ability to load arbitrary JavaScript, but you could also capture that deployJava.js and have that be local as well. Might be worth a look.

🌐
Team Treehouse
teamtreehouse.com › community › linking-files-to-html-and-java-script
Linking files to html and java script (Example) | Treehouse Community
July 5, 2022 - <script src="second-app.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <body> In this example, there are 2 linking script files. I've used 2 app.js files as an example but you would have the main script file as the last one. Be aware that the files are read one by one by the browser so 2 functions of the same name in different files are overridden by the other. Posting to the forum is only allowed for members with active accounts.
🌐
Reddit
reddit.com › r/java › run any java in html pages with one line of
r/java on Reddit: Run any Java in HTML pages with one line of <script>
September 5, 2025 -

I've created a simple JavaScript file that lets you turn any element in an HTML page into an embedded Java editor/runner with one line of JS code. You simply add this call in a <script> tag:

SnapCode.addPlayButtonToElementForId(myId);

This adds a 'play' button to the named element, and when clicked it takes all inner text and opens it in a SnapCode frame and runs it as Java REPL. Here's an example of a simple Java tutorial page that has been made fully live Java with a couple lines of <script> code:

Here's a sample link: https://reportmill.com/shared/learn_java.html

There are a ton of really cool things about it:

  • It runs entirely in the browser client (no sever needed)

  • It supports console input, graphics, animation, UI and even Swing

  • It allows full editing with code-complete, error checking, etc.

  • It can take you to the full SnapCode IDE

[Edit:] Here is a link to instructions how to do this.

Find elsewhere
🌐
Quora
quora.com › How-can-we-run-a-Java-program-into-an-HTML-coded-website
How can we run a Java program into an HTML coded website? - Quora
Add TeaVM to your build (Maven/Gradle), configure entry point. Compile Java into JS artifacts. Include generated JS in your HTML and call exported functions.
Top answer
1 of 11
53

If you want to do that yourself, without using any external library, a clean way would be to create a template.html file with all the static content, like for example:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>$title</title>
</head>
<body>$body
</body>
</html>

Put a tag like $tag for any dynamic content and then do something like this:

File htmlTemplateFile = new File("path/template.html");
String htmlString = FileUtils.readFileToString(htmlTemplateFile);
String title = "New Page";
String body = "This is Body";
htmlString = htmlString.replace("$title", title);
htmlString = htmlString.replace("$body", body);
File newHtmlFile = new File("path/new.html");
FileUtils.writeStringToFile(newHtmlFile, htmlString);

Note: I used org.apache.commons.io.FileUtils for simplicity.

2 of 11
13

A few months ago I had the same problem and every library I found provides too much functionality and complexity for my final goal. So I end up developing my own library - HtmlFlow - that provides a very simple and intuitive API that allows me to write HTML in a fluent style. Check it here: https://github.com/fmcarvalho/HtmlFlow (it also supports dynamic binding to HTML elements)

Here is an example of binding the properties of a Task object into HTML elements. Consider a Task Java class with three properties: Title, Description and a Priority and then we can produce an HTML document for a Task object in the following way:

import htmlflow.HtmlView;

import model.Priority;
import model.Task;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;

public class App {

    private static HtmlView<Task> taskDetailsView(){
        HtmlView<Task> taskView = new HtmlView<>();
        taskView
                .head()
                .title("Task Details")
                .linkCss("https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css");
        taskView
                .body().classAttr("container")
                .heading(1, "Task Details")
                .hr()
                .div()
                .text("Title: ").text(Task::getTitle)
                .br()
                .text("Description: ").text(Task::getDescription)
                .br()
                .text("Priority: ").text(Task::getPriority);
        return taskView;
    }

    public static void main(String [] args) throws IOException{
        HtmlView<Task> taskView = taskDetailsView();
        Task task =  new Task("Special dinner", "Have dinner with someone!", Priority.Normal);

        try(PrintStream out = new PrintStream(new FileOutputStream("Task.html"))){
            taskView.setPrintStream(out).write(task);
            Desktop.getDesktop().browse(URI.create("Task.html"));
        }
    }
}
🌐
Sololearn
sololearn.com › en › Discuss › 1119761 › how-do-i-put-my-java-code-into-html
How do I put my Java code into HTML? | Sololearn: Learn to code for FREE!
A while ago there was something called java applets, which were java apps you could insert into your html, but browsers stopped giving support to it due to security reasons, so now you can't. unless you manually activate them, if your browser allows you. Here's an official answer on how to activate it: https://java.com/en/download/help/enable_browser.xml Here's how to implement them in your html: https://docs.oracle.com/javase/8/docs/technotes/guides/jweb/applet/using_tags.html
🌐
Sololearn
sololearn.com › en › Discuss › 2087644 › how-to-insert-java-code-in-html
How to insert Java code in HTML | Sololearn: Learn to code for FREE!
December 3, 2019 - We cannot insert java code in html but we can insert html code in java using applet and then just compile your code with javac compiler and after creating bytecode just get output with appletviewer filename.class
🌐
Quora
quora.com › How-do-I-link-a-Java-in-HTML
How to link a Java in HTML - Quora
Answer: Nowadays, the best way to add Java to HTML is through the so-called JavaServer Pages (JSPs). A JSP page is a file with the extension . jsp. It is an HTML markup containing several JSP tags
🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › how-do-i-run-a-java-file-in-my-html-site-742957
[SOLVED] How do I run a .java file in my .html site?
I'm new to html and java, my site is http://www.members.cox.net/a.svorovski . I've been trying all day to find a way to run a .java file on my .html
🌐
Quora
quora.com › How-would-I-include-Java-code-into-my-HTML-code
How would I include Java code into my HTML code? - Quora
Answer (1 of 2): A̲l̲r̲i̲g̲h̲t̲,̲ ̲s̲o̲ ̲y̲o̲u ̲w̲a̲n̲t̲ t̲o̲ ̲i̲n̲c̲l̲u̲d̲e̲ ̲Ja̲v̲a ̲c̲o̲d̲e ̲i̲n̲ ̲y̲o̲u̲r̲ ̲H̲T̲M̲L̲—̲f̲i̲r̲s̲t̲ ̲t̲h̲i̲n̲g̲ ̲t̲o̲ ̲*̲*̲no̲t̲e̲*̲*̲ ̲i̲s̲ ̲t̲h̲a̲t ̲J̲a̲v̲a̲ ̲i̲s̲n’t̲ ̲r̲u̲n̲ ̲d̲i̲r̲e̲c̲t̲l̲y̲ i̲n̲ ̲t̲h̲e̲ ̲b̲r̲o̲w̲s̲e̲r̲ ̲l̲i̲k̲e̲ ̲J̲a̲v̲a̲S̲c̲r̲i̲p̲t̲.̲ ̲Y̲o̲...
🌐
Quora
quora.com › How-do-I-connect-Java-code-to-my-HTML-page
How to connect Java code to my HTML page - Quora
Answer (1 of 9): In order for you to connect Java to HTML pages, you are going to have to implement a JEE or JSP/servlet-based web application. There are several ways of building such a structure, one of which is the Spring Framework.
🌐
Quora
quora.com › How-do-I-add-Java-codes-in-HTML
How to write a Javascript code in the HTML page - Quora
August 3, 2018 - Answer (1 of 22): The tags. Example [code] [/code]JavaScript in or You can place any number of scripts in an HTML document....
🌐
Aspose
kb.aspose.com › html › java › how-to-create-html-file-using-java
How to Create HTML File using Java
December 26, 2021 - In order to generate HTML file using Java, first we will create the default HTMLDocument Class instance. Using createTextNode method, we will add desired HTML text for the document.
🌐
YouTube
youtube.com › watch
How to Link Java File to Html - Step by Step - YouTube
How to Link Java File to Html - Step by Step | 🔒 Surfshark VPN Deal — Stay private and secure. $1.99/mo + 3 Months Free ▸ https://theslopfarm.com/SurfsharkL...
Published   December 10, 2025
Top answer
1 of 2
4

I won't go by your code. But the example here will be enough. The standard way of passing/submitting data to the server in the pure Servlets/JSP world is by using HTML form, i.e. the same way as when use other server side languages for example php. And it doesn't matter whether it is a pure HTML page or JSP page. The recommended/most used method of submitting data from the form to the server is POST or GET. Its standard way to submit data using POST method and respectively to process the submitted data using the doPost() method in your servlet. for example:

<form name="something" method="post" action="<servlet-name>"> //if u want to change the action to something else then u need to modify your xml file.
<input type="text" name="username"/>
<input type="submit" name="submitit" value="submited"/>
</form>

now in the servlet under the doPost(...) write

if(request.getParameter("submitit").equals("submitted")){
String username=request.getParameter("username");
//now u can run a query and insert ito to database;
}

in the end you can redirect it another page with

`response.sendRedirect();`

or any other way may i assume that you are using eclipse Java EE ide for development. then u need not worry about integrating them, eclipse would prepare the xml files for you once you create a new Java EE project. and if not then u have to do it manually, i once tried to do it, but I couldn't succeed. here is a link: that would interset you, i hope: http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

this is bad thing, but i will edit the code for you. by the way, i am removing the javascript. KISS (keeping it simple silly).. :) ur jsp page would be:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <title>FORM</title>

    </head>
    <body>
        <form action="test1" method="post" >
            <table>
                <tr>
                    <td>First Name: </td>
                    <td><input type="text" name="name" maxlength="10"></td>
                </tr>
                <tr>
                    <td>roll:</td>
                    <td><input type="text" name="rollno" maxlength="5"></td>
                </tr>
                <tr>
                    <td>class:</td>
                    <td><input type="text" name="class" maxlength="10"></td>
                </tr>
                <tr>
                    <td>Mobile:</td>
                    <td><input type="text" name="mobileno" maxlength="10"></td>
                </tr>       
                <tr>
                    <td></td>
                    <td><input type="submit" value="Submit"></td>
                </tr>
            </table>

        </form>
    </body>
</html>

and the servlet will be:

import java.sql.*;  


class test1 {  
        public static void main(String[] args) throws SQLException, ClassNotFoundException  {  


            Connection con = null;
    PreparedStatement pstmt = null;
            try {  
                Class.forName("oracle.jdbc.odbc.JdbcOdbcDriver");  
            }  
            catch(ClassNotFoundException ex) {  
                System.out.println("Error: unable to load driver class!");  
                System.exit(1);  
            }  

            con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.106.87:1521:ORA11G","fuel_db","foel");  

String name = request.getParameter("name");
        String roll = document.getElementById("rollno");// idk why roll no is string
        String clas_s = document.getElementById("class");
        String mobile = document.getElementById("mobileno");  
try {
           String query= "INSERT INTO student (name, rollno, class, mobileno) VALUES (?, ?, ?, ?);";  
pstmt = con.prepareStatement(query);
pstmt.setString(1,name);
pstmt.setString(2,roll);
pstmt.setString(3,clas_s);
pstmt.setString(4,mobile);
           pstmt.executeUpdate();  

           con.close();  
    }
catch(Exception e) {
e.printStackTrace();}

response.sendRedirect("confirm.jsp");

       } 
}

donot ask me about the braces.. fix it yourself.

2 of 2
0

First create some method like submitData(data) in your Java class.

public class test1 {  

        public void submitData(String name,String rollno,String classData,String mobileno) throws SQLException, ClassNotFoundException  {  


            Connection con = null;  

            try {  
                Class.forName("oracle.jdbc.odbc.JdbcOdbcDriver");  
            }  
            catch(ClassNotFoundException ex) {  
                System.out.println("Error: unable to load driver class!");  
                System.exit(1);  
            }  

            con = DriverManager.getConnection("jdbc:oracle:thin:@192.168.106.87:1521:ORA11G","fuel_db","foel");  
            Statement statement = con.createStatement();  

           String command = "INSERT INTO student (name, rollno, class, mobileno) VALUES (" + name + "," + rollno + "," + classData + "," + mobileno + ");";  
           statement.executeUpdate(command);  

           con.close();  
       }  
} 

In your HTMl page index.html or index.jsp, you need to put a form and then post it to JSP page which has the logic I have mentioned below.

<FORM NAME="form1" ACTION="ProcessData.jsp" METHOD="POST">

In your JSP page you may get data when a form is submitted using POST method. Get all those variables using request.getParameter("name")

Then in your JSP put that java code in <% %> blocks inside body tag. Remember JSP is Java in HTML! In your ProcessData.jsp

<%
String name = request.getParameter("name");
//add null checks and all
//Similarly get all datamobileno etc
//then call your submitData() method
test1 myTest = new test1();
myTest.submitData(....)
%>

Also take care of naming conventions.

In java

  1. Classes name start with Caps. So class name must be Test1 and not test1.
  2. Functions, variables must be in Camel case like myTest.
🌐
Reddit
reddit.com › r/learnprogramming › how to link backend (java) to frontend (html, js, css)
r/learnprogramming on Reddit: How to link backend (Java) to frontend (HTML, JS, CSs)
October 18, 2023 -

Hey everyone! I am a beginner programmer (started 1,5 months ago) and I just followed some tutorials and managed to create the front end of the login and registration of the user, using html, css and JS (with VS Code). I was also able, with some more tutorials and intense research, to create the back end of a page with login and registration using Java (with IntelliJ) and it also works. But I can not find a way to link/connect these 2 files in order for the website to work. I have watched many videos but none seem to fit my case (prob because of my lack of knowledge). I have found a tutorial that might work, but I would need to convert all my html css and JS to JSX. Can someone please help me with what/how is the best way to do this? Ps.: I know it is very soon for me to want something like this, but I really need it.

Top answer
1 of 3
3
It's hard to say without knowing exactly what your code looks like but you basically just need to point your frontend at your backend. If you are just writing raw javascript you can use something like jquery or XMLHttpRequest to get started. If you are using some sort of js framework or something there might be an http client built in that you can use.
2 of 3
2
There are essentially two options You build a separate frontend in html/css/js and a separate backend API in Java, the frontend makes http requests through fetch/axios/etc to the backend API this is how the two communicate, these two can be on completely different servers and they do t really care what the other is made of as long as they can talk to each other using http/json. Frontend frameworks like React are popular for this style although not strictly necessary you can make simple html page & fetch requests or jquery to talk to the backend. If you look up Spring Boot + React tutorials you will find this style or whatever frameworks you want to use. Option 2, the more "traditional" approach there is no separation between the two, the Java application will generate the html and serve it directly to the user some might call this server side rendering usually using some sort of templating engine, the two are very much tied together. Depends on what you are using as the backend framework but you can look up Spring Boot + Thymeleaf tutorials. This is also what JSP/Servlets essentially does but I get the feeling JSP is falling out of favor.