This is my JSP file.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
//JFileChooser filechoose = new JFileChooser();
JFileChooser filechoose = new JFileChooser("D:\\");
filechoose.showOpenDialog(null);
File file = filechoose.getSelectedFile();
XLCauHoi.ImportXmlFileToData(file);
%>
<h4> Đã xuất file thành công </h4>
</body>
</html>
My problem is that: the JFileChooser pops up 2 times when I run it on browser. If I run it in a Java class, JFileChooser pops up 1 time.
What is my problem and how to solve it?
There's a major misconception here. First thing, JSP/Java runs at the webserver, produces a bunch of HTML/CSS/JS and sends it to webbrowser. Webbrowser retireves HTML/CSS/JS and interprets/applies/executes it. It doesn't run any line of Java code because it has already been executed on the webserver. Rightclick page in webbrowser and choose View Source. Do you see it? If webserver has done its job right, you should not see any line of Java code in there. The webbrowser namely doesn't understand it. It only understands HTML/CSS/JS.
Using a JFileChooser in a JSP scriptlet would technically only "work" when both the webserver and webbrowser runs at physically the same machine. It's basically the webserver which displays the dialog, not the webbrowser. This would only "work" when you're locally developing, but never when you publish the website into world wide web by a standalone webserver.
To upload files by HTML, you need an <input type="file"> element, not a JFileChooser. For more detail how to use it with JSP/Servlet, check this answer.
As to the concrete problem, I have no idea why it pops 2 times, but that should be your least concern in this particular case.
Related
Basically I'm running some automated tests using TestNG.
I'm using ITestListener to give real-time results of my tests status but this is outputted to the console.
Is there anyway of outputting the information on the console to a HTML file so I can view the progress from the html file?
I'm planning to create a HTML style report for my own benefit so more specifically would it be possible to place to output to specific parts of the HTML Report I create?
Overall I'm trying to achieve is a HTML file that I can open on Chrome while my tests are running and with an automatic refresh I can view the progress of the tests.
I came up with a solution that uses a small amount of JavaScript to update your browser window:
Your major file would be:
<html>
<head>
<script>
function loadContentFile()
{
document.getElementById("content").innerHTML='<objecttype="type/html" data="content.html"></object>';
}
window.onload = setInterval(loadContentFile, 1000);
</script>
</head>
<body>
<div id="content"></div>
</body>
</html>
Edit:
Your Java program would write to a file called content.html. Just like you have done before. Nothing changes there. The "magic" happens by calling the index.html instead of the content.html. The index.html file when opened with a browser periodically loads the content of the content.html file thus realising a automatic reload of the page.
Conclusion: You have a folder containing the index.html and content.html.
Your browser calls the index.html. Your Java program writes to the content.html.
I've written a Java Applet (in Eclipse, if that makes any difference) and embedded it in a local HTML file (which I will include). The applet code shouldn't be necessary because the problem lies in my HTML. The local HTML file works fine on Chrome, but Chrome is ending support for Java soon, so I'm trying to use the file on Safari. Theoretically, it should all function the same, but the Safari throws a ClassNotFoundException, while Chrome still runs it smoothly. The error reads "ClassNotFoundException", and the detail reads "chaos.chaos.class" (see HTML). (If it's relevant, I'm on OS X 10.10.3, with fully updated everything (I believe)) And, apparently, I'm not allowed to post pictures, so I shall verbally describe the layout of my folders. The HTML file is in the same directory as another directory called 'chaos'. Inside this directory are the 'chaos.jar' and 'chaos.class' referenced in my code, along with 'Shape.class' which is not referenced but is necessary for the applet to run (it's referenced by one to the other files). Thank you in advance for any and all help and suggestions.
UPDATE: I have also tried the HTML file on Firefox, and it works seamlessly there too. But I don't really like Firefox all that much, so I'm still searching for the answer.
<html>
<head>
<title>
The Chaos Game
</title>
</head>
<body align="center">
<blockquote>
<applet code="chaos.chaos.class"
archive="chaos.chaos.jar"
width=900 height=900
title="Chaos">
</applet>
</blockquote>
<br/>
<font size = "3">
Written by ...
</font>
</body>
</html>
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