I have implemented a Java Applet.
I have exported the jar.
I signed the jar.
And it works if I put it on my server and use it with HTML.
But only in Firefox.
Here is the HTML:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Upload Test</title>
</head>
<body>
<object archive="applet.jar" classid="java:uploader/FileUpload.class"
codetype="application/java-vm" width="800" height="600"> </object>
</body>
</html>
I also tried it with this:
<SCRIPT type="text/javascript">
if(browser.value.getIndex("chrome") {
chrome.browser.enableFeature(JApplet)
});
</SCRIPT>
But still Firefox only.
I would really like for this to work in Chrome & IE9.
But these two only leave a space where the Applet should be.
I can even highlight it.
Are there things I have to add in my xhtml? Or maybe something in the Applet?
I found enough online about why Applets might not work, but nothing about why Firefox only.
As Andrew Thompson said, I need to use deployJava.js.
You can find it in this Oracle tutorial.
This tutorial describes in detail every step neccessary.
Now my Applet works on all three browsers (FF, Chrome, IE9) like a charm.
Thanks!
Related
I am trying to build my first web application using Netbeans, with the tomcat server.
Here is my code for the html portion:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!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>Unit Converter</title>
</head>
<body>
<div align="center">
<h1>Unit Conversion</h1>
<form action="convert" method="post">
Miles: <input type="number" name="miles" required />
<input type="submit" value="Convert to KM" />
</form>
</div>
</body>
</html>
Thats the entirety of my html code. Then I right-clicked on the project, made a servlet. Changed the Class name to something befitting the project. Location: source packages, and picked the default one for Package, then went to the next page(called configure servlet deployment)... left most of it the same, changed the URL pattern to /convert.
Then it makes the servlet, HTML page WORKS! The button on the html page gives that error before I even add my own code to java. I added my code to java and still error. I have built many times, ran many times.
Not sure what I am missing, I looked around and I may be missing a web.xml file but it never generates one for me.
Edit: Changing "convert" to "/convert" in the html file did not work :(
Edit2: Before posting, dont believe the "page" made by this post, my html code works.
Have just finished programming my first Java Applet. How can I share this with my friends without them using eclipse on my computer?
I have 12 classes in eclipse. I have seen some examples of people using HTML to embed their applet in a website, but
A) I have only found examples with only one class.
B) I tried following this method: http://www.oxfordmathcenter.com/drupal7/node/37
but when I click on the html file, it just opens the html code in my browser, not the applet.
This is the HTML file that I made
<html>
<head>
<title>
World Cup Game
</title>
</head>
<body>
<h2>World Cup Game</h2>
<applet
codebase=“https://www.dropbox.com/s/lcojvh8tm2mukzn”
archive = “WorldCup.jar”
width = 800 height = 600>
</applet>
</body>
</html>
I don't mind whether I share it embedded on a web page or if I send them an executable jar file or whatever, but does anyone know how I can share my hard work!? Thanks :)
(Apparently executable jar file isn't an option with applets though...)
Of course it is an option:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title>My Applet Page</html>
</head>
<body>
<applet code="ClassFile.class" archive="YourJar.jar" width="400px" height="400px">
Java is not installed on your machine or your browser does not allowed Java Applet to run<br /><br />Get the latest Java technology at http://www.java.com/
</applet>
</body>
</html>
But I would not use that. Servlets are much better idea. Applets are client side thing if you do something that do not have to be processed on back-end why not but I did not see any applets for couple of years...
If you dont see your applet then probably you have public static void main(String[] args) instead of public void init() that also could make you problems
The basic Problem about applets are that they need jvm oriented browsers to run.
due to this reason applets(java) failed. today servlets are considered. you would need eclipse or any jvm for your browser to run..
I read already a lot of topics like this or this on stack overflow without no luck.
So what is going on. I have an applet that I created in Netbeans. It works fine until I insert an image in it as icon. My os is MAC and I use Firefox.
In Netbeans the applet looks ok when I run it. The problem is that in Firefox I see just a gray BOX instead of my applet.
Does anyone have any idea what is going on here?
So my HTML file looks like that:
<HTML>
<HEAD>
<TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<H3><HR WIDTH="100%">Applet HTML Page<HR WIDTH="100%"></H3>
<P>
<APPLET codebase="classes" code="slipapplet/SlipApplet.class" width=880 height=650 archive="/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/swing-layout-1.0.4.jar,/Users/Serial/NetBeansProjects/SlipApplet/build/classes/slipapplet/AbsoluteLayout.jar"></APPLET>
</P>
<HR WIDTH="100%"><FONT SIZE=-1><I>Generated by NetBeans IDE</I></FONT>
</BODY>
</HTML>
This is code about the label with icon in java:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Users/Serial/NetBeansProjects/SlipApplet/src/slipapplet/kemp.jpg")));
And the HTML file is in an upper file then everything else..
I am trying to embed a swing applet into our website, but it is not working. I have been able to get applets that use awt to do graphics to work. The web page that contains the applet only shows a blank box that should contain my applet, there aren't even any error messages. My applet works fine in netbeans. The applet is supposed to show a few buttons and a text field. I really don't know whats going on.
The web page is located at http://nuevawave.org/sandbox/JavaGallery/GUIApplet.html
The applet is at http://nuevawave.org/sandbox/JavaGallery/TestApplet.jar
Here is the html:
<html>
<head>
<title>Test Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<applet Archive ="TestApplet.jar, swing-layout-1.0.4.jar"
Code="test.GUIApplet"
WIDTH="250" HEIGHT="300" >
</applet>
</body>
</html>
as I wrote in the comments it works for me (I'm using OpenJDK 1.6.0_22, Linux (ubuntu) and Firefox).
If java works from your "command line" or terminal. I could be that the plugin for your browser isn't installed. I would recommend you reinstalling the JDK or JRE and remember to install the plugin for the browser aswell.
You can use the <object> tag instead. To know how to use this, check this link
OK, so I am trying to set up a simple JSF application. I'm using NetBeans 6.8, Glassfishv3 and Maven2. I made a JSP document like so:
<?xml version="1.0" encoding="utf-8"?>
<html xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<f:view>
<head>
<title><h:outputText value="#{Welcome.title}"/></title>
</head>
<body>
<h:outputText value="Welcome"/>
</body>
</f:view>
</html>
Problem is, if I navigate to this page (http://myHost/myApp/faces/welcome.jspx), it is returned as an XML document, but with the ${Welcome.title} value populated:
<?xml version="1.0" encoding="UTF-8"?>
<html><head><title>Gymix - Welcome</title></head><body>Welcome</body></html>
In Internet Explorer this looks like I would have opened an XML document. In Google Chrome the title is printed next to the text Welcome and instead of the title the URL to the page is printed on the tab.
If I change the JSP document to a plain JSP page (taglibs instead of xmlns and so on) it works and I get a proper page returned. Any ideas on what's wrong? Thanks!
Edit: sadly none of the quick fixes fixed this, so I'll look into this more. BTW, my pom.xml has jsf-api and jsf-impl dependencies with the version for both set to 1.2_14
Aside from the fact that you need to set the proper doctype and content type so that the browser knows what to do with the page, you also should get rid of the old fashioned jspx format and use xhtml format to get the most benefit of Java EE 6-shipped JSF 2.0 and Facelets.
The given code should be changed to:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>#{welcome.title}</title>
</h:head>
<h:body>
Welcome
</h:body>
</html>
Note that the doctype is included and that JSF 2.0 / Facelets will automatically take care about the right content type with help of the <h:head> component. Also note the absence of the <f:view> tag, this isn't needed anymore in Facelets.
You probably also need to reconfigure your webapp to make use of the full powers of JSF 2.0 and Facelets. To learn more about JSF 2.0 and Facelets, I strongly recommend to go through the Java EE 6 tutorial part II chapters 4-9.
Good luck.
Update: as per the comment of bobince: I would add an important note; it is true that the XML declaration (the first line) would mess the rendering mode of some webbrowsers (also see the site behind the doctype link here above), but that's certainly not an issue here. Facelets removes the XML declaration during generating the HTML of the page. The XML declaration is simply there because Facelets needs to parse the page using a XML based tool first. We're talking about a component based MVC framework and XML based templating technology, not about a plain vanilla HTML page ;)
I think you need to put in a valid doctype.
This would go below your xml declaration:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
You have to tell the browser what you're sending. I'm not exactly sure of how to do it inside a JSP though, so you'll have to figure out yourself or wait until someone more knowledgeable than me tells you.
You have to send the Content-Type HTTP header indicating your file is a text/html; charset=UTF-8.
Content-Type: text/html, charset=UTF-8