How to integrate java apis with HTML pages - java

I have a jar file which i want to integrate with web page and run on web browser (my be chrome). So what i want to do is calling a java API which will give me some data using which i want to populate web page. so the java code will run in the background. Now user can select any one of the option from web page and i want to send user input through java API.
Only thing i can think of currently is through java applet. Is there any other way to do this. May be something similar to applet already available in the market.

Related

Communication between frontend (jsp webpage on localhost) and backend (java program) using eclipse

I am new to front end developing. I have so far a back-end program written in java with Eclipse that does all I want, saves the output in an object and prints it in the console (for my convenience).
My goal is to display this output information dynamically (meaning that the backend part of the program might update and send new output) in a webpage on a local server.
Hence I have "transformed" or "added" a Dynamical webpage to my Eclipse project using "Project Facets" in Eclipse Project Properties, and created an index.jsp file hosted on a tomcat server (See picture of the File organisation).
Ultimately, I want to have my index.jsp file open in my browser and when my backend program (which I assume I have to compile in an executable jar) detects changes , display those changes in the webpage. Also, I have a button on my webpage for which I would like to send information back to my backend program when it is clicked.
Should I use POST request in my backend with the URL of the index.jsp (although I don t want to display the information in a form, just regular text and images)?
or create a Javabean class in the webcontent/WEB-INF/ (if I can access and modify it dynamically from my backend) and then use that to get and set data from the jsp page?
or am I obliged to use something like Spring ?
I ve heard I should seperate backend and front end, but I don t really understand how they communicate dynamically !
Thank you for your help !
Seeing your project structure I believe you want to build a simple Java Web, you don't need to separate your front-end and back-end unless you want to build something complex.
I'm not quite sure about your experience with Java Web, but if this is your first time I suggest to learn more about Servlet because this is the fundamental in building Java Web project. After knowing how Java handle Http Request is up to you to build pure Java Web project, or using something like Spring MVC even if you want to build a separate front-end that communicate using REST API towards the back-end.

Run an event referring to an external web page ..?

I ask you how to run an event related to an external web page.
In this case the external web page is the following: https://tools.pdf24.org/en/webpage-to-pdf
The web page converts the URL of web pages to pdf.
I want to programmatically execute the generation of PDF, considering that I have a list of web page that I need to be in PDF.
I ask if you have a tool in PHP, JQUERY or JAVA.
Where you can execute the generation of PDF by means of the external web page.
Thanks
At the time of this writing there are a couple of options, wkhtmltopdf and jsPDF.
wkhtmltopdf is a commandline line tool that uses the webkit engine to create PDFs from an HTML source. There are also multiple server side libraries and wrappers for this that you can use.
(link at time of writing) https://wkhtmltopdf.org/
jsPDF is a client side library that accomplishes what you're asking.
(link at time of writing) https://github.com/MrRio/jsPDF

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

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.

how to download 'generated source' from web developer toolbar in firefox

I want my java program to see the 'generated source' of a webpage, in Web Developer Toolbar: https://addons.mozilla.org/en-US/firefox/addon/web-developer/
in FireFox, found under the 'view source' menu, as opposed to simply the actual html source which regularly returns itself through java networking:
HttpURLconnection.getInputStream();
Can a java program do this, or at least delegate the task to another application on the same computer, written in something else (javascript) which gets embedded in the browser?
selenium should be able to do that. i used it a long time ago so i don't remember how exactly. but it's basically a browser plugin and some server code which communicates with the plugin. you can communicate via a java driver with the server and control the browser content and also get all the data from the DOM.
EDIT:
depending if a "real" browser is not necessary you can also use htmlunit which is basically a gui less browser in java.
If by "generated source", you mean the full DOM of a working web page, including elements that have been added, removed or modified by javascript in that page, then there is no way to do this without using a full browser engine to first render the page and then some sort of communication with that page or engine to give you the HTML for the generated page.
You could not do this with java alone.
You could put javascript in the web page itself which would fetch the innerHTML of the whole web page after it was fully generated and then use an ajax call to send that to your server. You would have to stay within the limitations of the same-origin-policy (which doesn't allow you to make ajax calls to domains other than where the host web page came from).
You could also find some server-side rendering engine that could do the same on the server side that your java application could use/communicate with.

Categories

Resources