HTML Java applet integration - java

I know this has been asked multiple times already, and I have already tried to use all of the solutions that I could find, but I wasn't able to get any success. I have a JApplet that works successfully (I've pasted the heirarchy below, as I don't think the code itself is relevant to the issue. I might be wrong). I also have some basic HTML code that seems to be correct based on the solutions that I have found. The problem is that I continue to get the same error:
(source: gyazo.com)
And I'm not sure why I'm getting it. Is it because everything in the heirarchy is a .java file?
my HTML file:
<html>
<head></head>
<body>
<applet width="950" height="600" archive="test.jar" code="OneQuestMapgen.OneQuestMapgen.class"></applet>
</body>
</html>
Hierarchy:
Files:
Any help would be appreciated. Thanks so much!

Can you try..
<applet width="950" height="600" archive="test.jar" code="OneQuestMapgen.OneQuestMapgen.class">

First, you need to close you <head> tag with </head> and do the same with the <body> tag.
Also, the <applet> tag has been deprecated in HTML4.01 and is not allowed in HTML5, so you should replace for <object> tag
So, if you are using it on Chrome, for instance. It will NOT work.

If your applet is in the same dir. as the html file you don't need to specify it as the browser searches for a location of the document in the same dir, if you have it elsewhere then it's ok to have the archive which should containt the path to the jar file.
Beside that you should consider adding to the code attribute also the package in which your class resideds, all separated by a dot code="OneQuestMapgen.OneQuestMapgen.class"

Shouldn't your html be like this?
<html>
<head></head> <!-- closing the head before the body -->
<body>
<applet width="950" height="600" code="OneQuestMapgen.OneQuestMapgen.class"
type="application/x-java-applet;jpi-version=6"
archive="test.jar">
</body>
</html>
in html5 it should be something like
<object type="application/x-java-applet" height="600" width="950">
<param name="code" value="OneQuestMapgen.OneQuestMapgen.class" />
<param name="archive" value="test.jar" />
Applet failed to run. No Java plug-in was found.
</object>

Related

CSS JS and Links not loading when deploy Spring boot as war in Tomcat

I have a Spring boot web application, it works fine when running as executable jar, but when I build as war and deploy to Tomcat, the css, js files are not loading and looking into further, I found out all links are pointing to root context path "/", I tried changing base href = "./" this fixed the problem of loading css and js, but I need to do that in lot of pages.
Also the links in <a> still points to root context path and to make this work I need prefix'./' . Below are my code snips,
CSS and JS link
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.css" rel="stylesheet">
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Tag
<a class="topHeader" href="/activateAccount"></a>
Is there a shortcut to fix this problem or should I change <base href> and <a href> in all the pages? Any help is highly appreciated.
There is no short cut or quick fix for this, I removed "/" in links in all anchor tags and that worked for me.
Example
<a href="/resetPassword" style="float: right;">
changed to
<a href="resetPassword" style="float: right;">

CSS not loading in spring boot application

I have been searching all day, moved the style.css everywhere and still not managed to get it loaded. The images wont load as well.
My structure:
But if i click the firefox button, it loads:
This is how the style.css is imported in the head of the index:
(tried all kind of combinations)
When i check the developer tools, it says 404 for GET request (style.css and the pictures)
Spring Boot knows where the static directory is, so you don't need to use the ../ technique to get to the files within. The other part is that you should be using an annotation to get there. It may depend on what view template you are using, but for thymeleaf this is how you would achieve pulling in the css file:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Your Title</title>
<link rel="stylesheet" th:href="#{/css/style.css}" />
</head>
Notice the annotation in th:href="#{/css/style.css}"
Make sure you include the namespace of your view template, th in the example.
Images work the same way:
<img th:src="#{/img/stanev2.png}" />

JSP Tomcat7 static css and js files not loading

Learning JSP and have an issue with the css/js content not loading. I have a jsp page, where I have bootstrap css and js referenced using standard html link and script tags:
<link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" />
and
<script src="/WebIntro/bootstrap/js/bootstrap.js"></script>
neither of them work and Chrome is giving me the following on the console:
Resource interpreted as Stylesheet but transferred with MIME type text/plain:
If I use an include directive, it works for the css but pulls all the content into the file:
<%#include file="/bootstrap/css/bootstrap.css"%>
The jsp has the following #page and meta tags:
<%#page contentType="text/html" %>
and
<meta http-equiv = "Content-Language" content = "en"/>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
I tried googling and found the mime-mapping element for the web.xml but the following seems to have no affect:
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
If there is some standard Tomcat config that needs to happen I am unaware as I am new to Tomcat; using Tomcat 7, and eclipse and this is in a maven project.
The solution for me was very strange. The changes to the web.xml file that was present since I built the project in eclipse/maven, weren't reflected in the web.xml within tomcat webapp application directories. Everything else in the package updates fine (as far as I can tell), except for the web.xml?
So I found the web.xml file within eclipse inside target >> project-SNAPSHOT >> WEB-INF >> web.xml (which is supposed to be derived). Forced changes there and it worked, changes were picked up and my original issue gone.
I am guessing I had inadvertently broken some type of dependency link or something along the way somehow, but once I added the servlet, mappings, etc back in, everything worked fine.
Weird.
Removing this line in jsp resolved the error for us.
We were facing the issue when using Tomcat 8.5.59

HTML embed not working for Java Applet

I've been researching on which to use between <applet>,<object>, or <embed>, but none seem to work.
When I tried to load JApplet through HTML I am got RuntimeException error java.lang.NoClassDefFoundError: com/sforce/ws/ConnectionException.
When I tried to run number1.class with the number1.class being in myfile.jar it needs the other 3 jar files for the library and that is what the error is. The files look like this:
tomcat-->webapps-->applet-->newhtml.html
applet-->lib-->(wsc-23,enterprise,partner)
applet-->applet_class-->(number1.class,myfile.jar)
Any help would be appreciated.
I've also looked through majority of stackoverflow questions as well as other places, but still no luck!
<!DOCTYPE html>
<html>
<body>
<html type="application/x-java-applet;version=1.6"
width="512" height="512"
code="applet_class.number1.class"
src="myfile.jar,applet/lib/wsc-23.jar,
applet/lib/enterprise.jar,
applet/lib/partner.jar"/></html>
</body>
</html>
The best way to deploy a JWS app. or applet is to use the Deployment Toolkit Script.
But looking at that element..
<html type="application/x-java-applet;version=1.6"
width="512" height="512"
code="applet_class.number1.class"
src="myfile.jar,applet/lib/wsc-23.jar,
applet/lib/enterprise.jar,
applet/lib/partner.jar"/></html>
The most basic form of the applet element (deprecated in HTML 4.01 is):
<applet
width="512" height="512"
code="applet_class.number1"
archive="myfile.jar,applet/lib/wsc-23.jar,applet/lib/enterprise.jar,applet/lib/partner.jar"/>
</applet>
Change html to applet.
Remove the type attribute.
Remove the .class from the end of the code attribute.
Change src to archive, and have all the archives in one line.

Java: JApplet, How do you embed it in a webpage?

I searched for this subject on Google and got some website about an experts exchange...so I figured I should just ask here instead.
How do you embed a JApplet in HTML on a webpage?
Here is an example from sun's website:
<applet code="TumbleItem.class"
codebase="examples/"
archive="tumbleClasses.jar, tumbleImages.jar"
width="600" height="95">
<param name="maxwidth" value="120">
<param name="nimgs" value="17">
<param name="offset" value="-57">
<param name="img" value="images/tumble">
Your browser is completely ignoring the <APPLET> tag!
</applet>
Although you didn't say so, just in case you were using JSPs, you also have the option of the jsp:plugin tag?
Use the <applet> tag. For more info: http://java.sun.com/docs/books/tutorial/deployment/applet/html.html

Categories