Open local html page - java - java

In one of my java console application, I am dynamically creating html page. Now I want to open it using default web browser. So can you guys please help me out to solve it.

Swing java.awt.Desktop.getDesktop().browse(uri);
SWT Program.launch(uri);
Taken from In Eclipse Plug-in, how to launch a web url using system broswer?
Assuming you have a file to open.

You should read Runtime it allows you to execute a launch of a program (your default browser for instance.

With Java, your website is dynamic, so you need a server to run your web application. The most common one is Apache Tomcat. You should read about Tomcat if you plan to program websites with Java.

Related

imitate browser with java

I'm looking for a java-framework which enables me to easily communicate with a website.
What I'd like to do is for example:
log into a website
open various pages
read information
submit information into forms
send ajax-requests
read ajax-response
What I'm not looking for is a browser automation plugin like selenium. I'm trying to have my application directly communicate with the website.
That's the general outline. If you can think of a better solution for the following problem, I'm more than willing to follow your advice (:
We're working with an webapplication with an gruesome GUI. Unfortunatley we've got no means to tinker with said application or request changes to it. What I'd ike to do is to build is a client which logs into said application, fetches the data and displays them in a more appropriate manner with additional information based on that data while also providing tools to process this data and submit it back to that web-application.
Thanks in advance.
Selenium does come for JAVA. You can download it from here. http://www.seleniumhq.org/download/
Here is a tutorial:
https://www.airpair.com/selenium/posts/selenium-tutorial-with-java
How Selenium web driver works
Selenium web driver (firefox web driver) will open a web browser(firefox) for you and you can actually see what's going on. The choice of opening a browser window may not be the requirement for you. Then you can use:
HTMLUnitWebDriver
PhantomJSDriverService
Take a look at
http://hc.apache.org/httpcomponents-client-ga/quickstart.html
Its not a framework but a library but should provide you the needed methods to interact with your web application

Possible to Run Normal Java File Via Browser?

I've coded a game in Eclipse (still working on it), is it possible to run it's jar file in browser so that anyone can play right from their browsers instead of downloading jar file?
I.e I upload it on my website so that anyone can play right from the link I provide them.
Consider using Java Web Start with JNLP. You can host a JNLP file on a web server somewhere, along with your jar, and users can use a desktop shortcut pointing to the link, or a browser to open your app. (Using a browser will require having a web page with an applet tag: the article mentions how to do this but doesn't separate the two.)

How to debug a Java project's JavaScript files inside Netbeans 8 itself ?

In Netbeans 8: a new HTML5 project using AngularJS online template lets me runs the html files with the debugger attached to browser and I can set breakpoints inside Netbeans JavaScript files to debug. Which makes things ALOT easier.
But when I create a Java maven based web project with AngularJS dependencies I have to use the browser's code viewer to debug the Javascript code. Which is more time consuming.
How can I debug JavaScript files inside Netbeans instead of debugging in the browser for a Java maven based web project ?
You don't / can't directly. While it is possible to run a Java based Javascript interpreter you won't have access to any browser windows or DOM elements. Instead, you almost certainly want to use EmbeddedBrowser to launch and control Firefox, Safari and/or IE depending on which you wish to test with in Netbeans. Note that it's running an external process to do this, and I don't think you'll be able to access the browser developer tools from within the embedded environment (which is what I normally use when debugging Javascript).

Allow user to download a file generated by Java applet using Javascript API

I have a Java applet embedded into a web page which generates a file that the user must download. I understand there is a way to do this by communicating with a Javascript API.
Could somebody please explain to me how to do it this particular way?
Javascript doesn't allow file saving just yet, and the hacks that "work" need modern browser that understands data URI:s. In that case you would simply send the binary data as base64 and make the browser navigate to the data URI by setting document.location.href = 'data:application/octet-stream...' The download prompt would look like this in firefox:
http://img824.imageshack.us/img824/5080/octetstream.png
Flash allows for real download/save dialogs though so you could also look into that... or find out if java applets have that too.
If the user can be expected to have (or be willing to upgrade to) a Plug-In 2 architecture JRE (e.g. Sun's 1.6.0_10+)1, it is possible to launch the applet using Java Web Start. When an app. is launched using JWS, it can access the JNLP API, that offers file services that allow even sand-boxed code to save information to the local file-system.
Here is a demo of the JNLP files services.
That is if the applet needs to be embedded. JWS could launch applets free-floating since it was introduced in 1.2.

can i use java code as it is in a jsp file?

Please forgive me if my question sounds too dumb :(... I have created a java desktop application, which has a single UI screen in Swing... The application creates a pdf report... I want to convert this application into a jsp based web application. So do I just have to create a simple screen where the parameters required to create the report are asked, this screen replaces the swing based UI... and the main block of java code (used to create the report with the help of input parameters) can be invoked from a jsp file? Is that it? Or is something more significant required to make this app into a web app. How do I find out what else is required?
You should have a web server. Create a web archive (.war) from your code base by reusing Java classes and new jsp file (UI). So your understanding is correct. and remember there won't be any main method now.
Yes - JavaSE code is the same Java on server side. You have to change UI. You may use plain HTML or web framework such as JSF.
This highly depends on your code. Business logic and PDF generation might be reused but the UI will definitely be replaced. You'd then also have to account for the download part, i.e. the response could be a page with the DL link or the generated PDF.
Edit: as Azodious already stated, you'd need a webserver like Tomcat (or JBoss which is a fully fledged application server and includes Tomcat) that is able to execute the Javacode, so just replacing the UI wouldn't help much.

Categories

Resources