I have just started to write applets and so have never embedded in a webpage before. I have 2 applets that on there own run fine however when I try to run the 2 applets in the same page only one is visible. This seems very strange I have tried using the opening and closing foo bar tags for each applet.
These applets have no connection to each other however I also found that the html tags were also ignored after the applet which threw the page design out as well, this has totally baffled me.
The code encasing the applets is
<div class="wholeframe">
<div class="lframe3">
<!-- content for left frame to go here -->
<h2>Basic Java Swing Applet</h2>
<br />
<applet code="org.my.form1.MyApplet" archive="java/form1gui/FormApplet1.jar"
height="60" width="250"/>
</div>
<div class="rframe">
<h2>Basic Java Swing Applet</h2>
<applet code="org.me.hello.MyApplet" archive="java/hello/HelloApplet.jar"
width="350" height="150" />
<!-- right frame div end -->
</div> <!-- whole frame to box 2 frames -->
I would be grateful if someone could advise where I have gone wrong as this should be simple to do and I am sure it is but I cannot seem to work out the issue.
The first thing I'd recommend is validating that 'HTML' with the W3C mark-up validation service. The reason I put the HTML in commas is because whatever that mess is pretending to be, it is not (valid) HTML.
(grumbles) Programmers tend to think that whatever rubbish they put in HTML should work. The real world is somewhat removed from this fantasy land.
Other recommendations:
Post a link to the applet, broken or otherwise. If we are feeling motivated, we can visit it, look at the (entire) HTML, download the Jars or classes, and test solutions.
Ensure the Java Console is opened automatically when loading applets. Without the console information, you are debugging this with 'one arm tied behind your back'.
While debugging, reduce the web page to the minimum. No headers, divs, code, CSS etc. Include that stuff once it is working.
To embed more than one applet in a single web page, put each applet in its own subfolder within the folder that contains the HTML document. Use the APPLET tag's CODEBASE attribute to specify the folder that contains the applet.
For example, to embed the applets 'Aplt1' and 'Aplt2' in the web page defined by the file TestAplt.html, you can set up the following files and subfolders in a folder named Test:
Test/TestAplt.html
Test/Aplt1/<Class files for Aplt1>
Test/Aplt2/<Class files for Aplt2>
For files in this structure, put the following APPLET tags in the file TestAplt.html:
<applet codebase="Aplt1/" code=Aplt1 width=16 height=400 align="left">
<param name=ParamAplt1 value="Aplt1.djr">
</applet>
<applet codebase="Aplt2/" code=Aplt2 width=32 height=400 align="right">
<param name=ParamAplt2 value="Aplt2.djr">
</applet>
Please use this link Multiple applets in a page
Related
I have one webpage and a file on a server. How to read from file on every page load. I m using jsp. Is there any function available to check page load?
Every page load means that you come to server every time (cache is another story).
So, jsp is loaded from the server every time and here is simple directive to include file to jsp:
<%# include file="foo.html" %>
Keep in mind that server knows only about jsp changes but not about foo.html changes. So, if you change only foo.html server doesn't know about it. That's the reason why this approach is not common. It is used mostly for common templates and parts of all pages (like common footer) even there are other better modern techniques to do so (like CSS).
However, if you still want to use external file which constantly changes just remember that JSP is Java too and you can use whatever you do in Java (except it is not recommended - JSP should be simple viewer in MVC).
So, something like this will work:
<% out.write(Files.readAllBytes("foo.html")); %>
You can use any techniques to read file and write it to the response output.
Addition for your comment:
Text field is regular html. Input to it would be like this:
<input name=abc value="<% out.write(Files.readAllBytes("foo.txt")); %>">
but, again, please consider more modern techniques like DHTML, AJAX, CSS or simple JavaScript.
I have been trying to incorporate my simple Java applet on a HTML page, but I haven't found any luck getting it to work. I have done some research on the matter and I have found some contradictory results.
My understanding is the tags <applet></applet> have been deprecated. I went to one site and I read that I needed to use the <embed></embed> tag. Then I went to another site and read that I needed <object></object> tags. Problem is I have used both of the tags <embed> and <object>, but I haven't succeed in incorporating my applet on my HTML page.
I am using the Eclipse Juno IDE for the java applet and Notepad++ for the HTML page.
<embed width = "60" height = "60" type = "application/x-java-applet;jpi-version=1.7.0" code = "SimpleApplet.class" > </embed>
<object width = "60" height = "60" classid = "clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" >
<PARAM name="code" value="SimpleApplet.class">
</object>
The best way to deploy a JWS app. or applet is to use the Deployment Toolkit Script. It will use whatever tag is most appropriate for that version of that browser.
I currently have a relatively simple Java applet which I am trying to embed into an html page. I've looked around, and haven't found a suitable answer. Many answers refer to using the deprecated <applet> tag, and the rest do not seem to work for me.
This is the body of my page. I initially tried using the <applet> tag and it worked, however I was unable to get it to use the full height of the page, and then I found it is deprecated anyways.
I've tried this on Firefox, Chrome, and IE, and it won't work on any of them. It only shows the alternative text.
I did read that the <object> tag only works for IE, but even so it isn't working for me. Likewise, most of the information I found is outdated.
<body>
<object width="500" height="500" data="project">Your browser does not support the <code>object</code> tag.
</object>
</body>
Ive had no problems using the applet tag to get applets to display to a desired width and height. All the Java resources point to using the same tags. I'm no html guru though, so I'm not sure if there's another solution.
<applet code= "myJavaApplet.class" width="600" height="700">textgoeshere</applet>
I have very little experience with HTML and applets. I have tried several of the things I found online, but am unable to make my Java applet run in a web browser (it functions in eclipse).
I have put the HTML file in the same folder as all of my Java class files for the applet. I am currently using Safari, but would like the applet to work in most any popular browser.
How can I display a java applet on a webpage using HTML/JavaScript? Can anyone offer any tips/advice?
Below is my attempted HTML code.
Attempt 1:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<embed code="PendulumApplet.class"
width="200" height="200"
type="application/x-java-applet;version=1.5.0"
pluginspage="http://java.sun.com/j2se/1.5.0/download.html"/></embed>
</Body>
</Html>
Attempt 2:
<Html>
<Head>
<Title>Pendulum Applet</Title>
</Head>
<Body>
<br>
<br>
<OBJECT
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
width="200" height="200">
<PARAM name="code" value="Applet1.class">
</OBJECT>
</Body>
</Html>
Try below code
<APPLET CODE=AppletSubclass.class WIDTH=anInt HEIGHT=anInt>
</APPLET>
OR
<object width="400" height="400" data="helloworld.class"></object>
Good Luck...
Use deployJava.js to write the applet element. The script is supported by Oracle, and will:
Check the user has the minimum required Java, prompting them to install if not, before..
Writing the object/embed or applet element as is best known for that browser.
Other notes:
Is it PendulumApplet.class or Applet1.class? It is hard enough to debug problems on international forums without introducing doubt about the name of the applet class.
The .class extension in the code attribute is tolerated, but not correct. The value should be a string representing the Fully Qualified Name of the class. E.G. javax.swing.JApplet as opposed to javax.swing.JApplet.class.
HTML element names should be all lower case (e.g. <html> as opposed to <Html>)
What output do you see in the Java console? When debugging applets in a browser, it is vital ensure the Java Control Panel is configured to pop open the console on discovering an applet (or JWS app.).
Although I have not done so myself, my Java textbook provides this outline for an embed:
<applet
code = "ClassName.class"
width = 250
height = 50
[archive = archivefile]
[vspace = vertical_margin]
[hspace = horz_margin]
[algin = applet_alignment]
[alt = alt_text]
>
</applet>
(Optional parameters in brackets)
I was having this SAME issue myself.
Using <applet code=""></applet> doesn't work, but <Applet> or <APPLET> seems to work.
Google Chrome and IE.
When I 'view source' using different browsers my web pages seems to always have lots of whitespace and are badly formatted. I am developing a Java web application using JSPs.
How can I ensure that when I 'view source' I see nicely formatted HTML?
Edit:
When I say formatted I mean typically:
I get this kind of thing:
<div>
<p>some text</p>
</div>
when I want:
<div>
<p>some text</p>
</div>
In my JSPs (which use includes) everything is formatted nicely.
View Source is only going to show whatever the page gives it in browsers that I know of, so if the HTML isn't formatted nicely, you won't see it formatted nicely.
Your best bet would be to use the developer tools in whatever browser you are in. The HTML is normally structed nicely in there when viewing the HTML. In Chrome or Internet Explorer, F12 should open the developer tools and I think F12 opens Firebug in Firefox if you have it installed.
Note: The source/HTML elements typically viewed by developer tools isn't exactly what the page spits out. They often show dynamic elements that were added through script and/or plugins.
Quick source viewer - Chrome Web Store
Altering generated html in a Java webapp is best done by a Servlet Filter. You can roll your own using whatever prettifying software you have to hand, or install one created by someone else, such as the JTidyFilter.
An advantage of this approach is that you can use the filter during development and remove it for production.
I know Chrome's developer tool have a "pretty print" feature for formatting javascript. I don't know about HTML, but you could look. I'm on a mobile device, so I can't.