Console output to HTML File - java

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.

Related

HTML Java embedded applet ClassNotFoundException in Safari but not Chrome

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>

Call an applet through a JSP site

I have create a simple Hello World Applet and I have save the .class file to the server where the JSP site is.
I want help so what I have to write in the JSP Site so whenever through the Browser I open this specific JSP Site this applet also run and show the message Hello world.
The JSP site and the .class file from the applet are at the same root, for example *D:\server\tomcat\test*
and also if someone can explain me what is the appletviewer and if I need something like this in my case?
You add an applet to an html page.
The jsp page gets compiled and when it runs its spits out html.
So in your browser all you will have is html.
So you basically need to embedd you applet to the html that is generated by your jsp page.
I would suggest you to do some research on adding your applet to html.
Once you have that, simply append the resulting html code (which has the applet) to your jsp page.
Embed the applet in the file by adding the following applet tag anywhere between the file's tags:
In an HTML file: <applet code="org.me.hello.MyApplet" archive="HelloApplet.jar"></applet>
In a JSP file: <applet code="org.me.hello.MyApplet" archive="HelloApplet.jar" width="600" height="480"/>
The jsp will ultimately spit out the html code.

Google App Engine - Is it possible to start the jvm upon accessing an html page?

I am currently building a (very) small website using Java and the Google App Engine. I know this website will never have more than 1 or 2 visits a day.
The problem I am facing is the very long (~7 seconds) first page loading. This is due from what I understand to the need to start a new Java virtual machine when the user first loads a page built from a jsp. I would like to avoid this user-unfriendly loading time.
For this small website, most of the pages can be static (i.e. only using html and css). There is just one page that needs to be dynamic (built from a jsp). Would it be possible to start the jvm when a user access an html page so that it is already running when he reaches the dynamic part of the website?
Just create some dummy endpoint (e.g. JSP returning just OK String) and call it after the static page is loaded using JavaScript. You can for example use following jQuery snippet.
<script type="text/javascript" src="http://codeorigin.jquery.com/jquery-1.10.2.min.js">
</script>
<script type="text/javascript">
jQuery(function(){ jQuery.get("/path/to/your/dynamic/dummy/page")})
</script>
See warmup requests. The easiest would be to create a new servlet that performs similar function as the JSP page.

How can i add my script from code behind to end of the file

I have script for Google Analytics in my master page at the bottom of the page.
it is just below the tag..... from the code behind i need to push some information to the google analytics. using the _gaq variable which there in that script.
sample: in my master page
i want to add my script after this script. i used RegisterStartupScript but the variable wich there in that .js is not loaded so that object throws an error undefined.
I dont have permission to move the google analytics script to above the tag.
if i use RegisterClientScriptInclude then one more copy of file i will load. that also not preferable. becouse google analytics shuld run after all page is loaded. so
How can i add my script from code behind to end of the file. after this script???
help me
Guru
You can to added javascript file at the end of the tags. so it run after all tag initialization.
<html>
<head>
</head>
<body>
/*
// your codes
*/
<!--added your google analytic script here -->
<script src='js/ga.js' type="text/javascript"></script>
</body>
</html>
It works let me know if not..

JFileChooser pop up 2 times

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.

Categories

Resources