Integrating backend code (Java, Python) with HTML [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm experienced with back-end code with languages such as Java and Python but for an upcoming project, I need to integrate this code to a website.
The backend code will be a bunch of methods and classes that will be able to encrypt text messages with encryption such as AES. For this project, this system must be implemented on the web.
I've been reading around and asked some people and it seems there are ways to use this Python or Java code on a webpage without having to rewrite it in something like PHP. I've seen some things like Django but I'm not sure what would be the best option for this project.
The webpage will simply do the following:
User selects an encryption type, gives key, and their message.
This message is then encrypted using their choice of key and encryption.
Suppose the encryption methods are already ready, how would I be able to connect the input on the webpage (text field, drop down menu, and button click) to my program and call the appropriate functions and display the returned values?
I'm sure this is possible but I'm not sure which option would be best for this task.
Thanks.

First of all remember that before reaching your server, the data has to pass from the user's browser to your server (i.e. over the Internet). If you want the data the user is sending to be encrypted on the way to your server then you need to set up a certificate and use HTTPS. This is irrespective of whether you are going to use Java, Python, PHP or anything else on the server side.
For what you need then, if you are using Java, what you would do is have a servlet container (such as Apache Tomcat) and develop a Servlet (which is a normal class that extends HttpServlet) and in its doPost() method, which receives the data from the user, calls your respective methods, and outputs the message (ideally in HTML format, enclosed in <html>, <body>, <p> tags)
You would also need to create a small HTML form (could be a simple HTML file if there is nothing dynamic in it and just has a form with a dropdown of the encryption choices and a text area where he puts the data). The action of the form would direct to the servlet above, that calls the encryption methods.
Both the servlet and the HTML file need to be bundled in a webapp war file, which is then deployed in Tomcat.
There are obviously much more details to this, but hopefully you have enough keywords to get you started with building a 'hello world' web application with a simple servlet.
I suppose there are similar things for Python too, make friends with Google!

Related

Can I call a .java file from a .html file with href or something else without using javascript in-between [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I want to call a java file(java class) from index.html using href without using java-script in-between html and java.
I am using springboot and my java file is inside src/main/java/controller and the html is inside src/main/resources/templates.
So anyone please help me to find whether it is possible or not,if yes then how can we achieve that.
Thanks in Advance..
Updated from OP comment:
Thank you very much for your reply and let me correct the question can
I call a function which is written in java directly from a html. –
JAVA Coder Nov 5 at 9:08
Still the same answer. Methods or functions, terminology aside. What you're proposing is like trying to power a bicycle by attaching an engine piston to it without the engine. Does not compute.
You cannot directly "call" a java process from html/js.
---- END UPDATE
No.
Longer answer:
Java files aren't called. Java classes are. The Java runtime has to live somewhere for java to be used. Typically that would be in your app server/web server. Its entirely possible to use java to generate the html, but the way your using the term "call" in this case doesn't make sense. Html doesn't "call" anything as its really just a rich text implementation (like a painting). Modern browsers implement javascript interpreters (which has nothing to do the Java) to run javascript code.
So, can you write html to "call" java (without javascript): No. Can you use java to generate html: Yes. Can you "call" java from javascript. Only if its are exposed as a web service (e.g. classes in the app server are configured to present http content)
A programming class and web services overview would probably be helpful.

Styling Java with HTML/CSS [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
So im fairly new to Java, anyway i have a implemented a simple Java program on IntelliJ which runs in the IntelliJ terminal, it basically ask the user to input some details and then records them along with the current time.
I now want to style it out using HTML/CSS to convert it into a webpage, where the user would enter the details into input boxes etc.
Im not sure how to approach this, what would be my best shot?
Also the user input is also being stored in a variable at the moment, would i have to use a database instead for a webpage?
Thanks.
Well I would recommend you to read first about what is Model-View-Controller paradigm in web page architecture, then you can probably better reply to yourself in terms of what you need for your webpage in order to do what you want.
I will grasp some about the things that you need:
You will need a database to store your user input details along with with the current time. (MySQL for example)
After that you need to define which type of data you need to save, you will have to make models in java for parsing those details from java to the db and vice versa.
Then you will need to create some services (You can learn about repositories before services if you need, which you probably would) to support those connections with the database in which you will retrieve data from DB.
A way to control how those services to serve your webpage is having a controller for processing the HTTP requests.
Last but not least, the controller will "glue" your jsp views with the data from services to be shown in your browser.
There will be many other ways, at least this is the way I know. I use Spring framework for building the MVC.
You have to do full stack page with java backend and html & css for the front-end.
Do a webservice with spring boot this generate a restful API to communicate with your web page using HTTP methods ( Get, Post, Put and delete ) and use AngularJS for example to parse the webservice created.
check out this : example
Quite simply, you'll need a web server to spit out HTML. I mean, there's lots of ways you could do it, but far and away the most popular is a web server.
There are lots of options for you. As an Eclipse fanboy myself, I can't say specifically, but a cursory google search yields this Tomcat plugin which should allow you to run a web server via IntelliJ. There are probably dozens of other plugins for differnt web servers you could use.
What you put into that server is up to you - it could be a simple html document populated by parameters, a REST endpoint, a JSP, who knows what. That's beyond the scope of the question - the first step is getting your web server up and running and then deciding the framework to use.

How to add java code into a Static web page? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to create a static web page (same content to all clients).
In the meantime, I want to run the site as follows:
- Double click on the html file. (So if I'm not wrong, I don't need server side, i.e apache tomcat).
(I want this for now, in order to make progress in logic)
The static web page will contains:
browse button
OK button
(by 1&2) when the user choose a file and click OK I want to open a tcp connection to a remote appliation and exchange some data.
Several Q's:
How can I use java code (to send/recive messages) in HTML files (after the user click on "OK") ?
Do I need to use JSP & TOMCAT ?
(I want somthing that will be use for my interest only, and will not be as a internet web page)
If you reliably want to run code on a web page without interacting with the web server to do so, you need to use a language native to the browser.
As of 2015 that would be Javascript (which is a very different language than Java).
Interacting with the web server is then typically done with AJAX calls, where the part of your code running inside the browser exchange data with the part of your code running inside the web server. The front end code is again typically written in Javascript and the backend code in whatever the web server supports.
Note that after you have done some initial experiments, most likely will need a framework to make this easier to do for non-trivial behaviour.
#1: I am not sure what you are heading for, but Google Web Toolkit could help. Basically it splits your application in a client and server part, all written in java, but the client part gets compiled to javascript. This way you can develop all in java and bootstrap it within ANY html page.
#2: Easiest way would be to write the server in java and host its war-file with a jenkins. But there are much more possibilities including a non java server.

Android App with Online Database [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i'm creating an app wherein the database are uploaded online without website, the concept of the app is like Waze app. I dont know where to start im asking for ideas and help. do i need to create a web server?how?i will mark this correct for those who can answer thanks.
This is not a simple task because it relies on many parts doing its proper job... In order to do what you want to do you need basically 5 things:
1.- Server: which will feed live information to the app.(There is a ton of servers that can be used to get this part done. If you are used to, or willing to learn php, I suggest you to start researching XAMPP (it uses Apache server running php stuff) [https://www.apachefriends.org/es/index.html]).
2.- Database: Most likely the server will need to work with information stored in some place. databases are perfect for just that. XAMPP also comes with MySQL which happens to be the most popular open source database out there.
3.- Format :You need to determine how the information will be passed from the server to the mobile device. The most common ways are: JSON which is plain text, XML that also is plain text but formatted diferently. this is important because you have to send the information from the server using this format and also your mobile devices will need to interpret the information in this format.
4.- Choose a way to send and recive the information : i would suggest Http/Ip protocol for this, as it is very common. Investigate Http requests and responses.
5.- Your device must be listening (or asking) for the content : the device will have to implement some sort of timer to ask the server for new information. This is determined by the logic and prupose of what you wish to do.
do i need to create a web server?
Yes! You need to create a web server, then, a webservice (database query etc...) which communicate between your application and your webserver. I think that all!

How to use Java in PHP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I want to use WordPress for my web development, which is PHP written, including the database connection to MySql. The whole thing is PHP. But I need to use Java to back-end data processing and a number of existing Java open source libraries.
A google search shows that PHP/Java Bridge is a way to go. Is that bridge best way to go? If everything is PHP with WordPress, is still a way to use J2EE technologies, inlcuding JSP, Servelet, etc?
edit
Java is needed becaue I need to run machine learning algorithms, libraries for which are only available for Java. Also, PHP may run into efficiency issues when it's used to process large amount of data.
A good example of libraries in Java I am going to use is those processing Big Data, which are mainly Java, like Hadoop.
The very simple answer here is don't
PHP is designed to, at every page request start up, execute a small series of scripts as a single operation, output the data associated with those scripts and then immediately die after generating the output. It literally does not have time to wait for your Java programs and libraries to do their thing, so don't try to put one in the other, which is why PHP scripts that rely on databases tend to have heavily optimised databases for immediate retrieval, instead of general databases that rely on joins and selects that take a few seconds to form the correct data response. Neither PHP or users browsing websites have time for that.
What you could do is wrap your java tools in Java Servlets and have them running on the same server/host that your PHP instance is running from, so that your scripts can access the Servlets as http://127.0.0.1:7254/... as it would any other restful API it needs to use while generating your script output, as long as you make damn sure that you're not going to make PHP wait: if it has to send data to your tools, that is a post-and-forget operation, PHP should not be getting any response back other than an immediate "data accepted" or "data rejected" before the data is then actually handled by your tools. If you need to post data and then get a result back, you're going to have to use two calls. One to post the data, and then a second call to request the result of that posting.
For instance:
web page generation chain: WordPress CMS based on PHP -> your database
web input for processing: WordPress CMS based on PHP -> Java Servlets for machine learning
data processing chain: Java Servlets for machine learning -> your database
So you build pages only based on what's in your data base, you post data to your java Servlets only to get them to start doing something and you don't wait for a response, their result will end up in your database and you'll get it for pages once it's in, and your java programs do what they need to do independently of your WordPress setup.
And if you're going to do that, you should probably write that functionality as a WordPress plugin that can talk to your Java Servlets.
And now you have a second project you need to work on: turning your java programs into web servers. Not terribly complex, but definitely something you're going to lose some time on doing right (because you'll need to wrap with servlets, as well as make sure you can have those running without crashing on the same server as your wordpress instance, which is always fun)

Categories

Resources