How to add java code into a Static web page? [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 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.

Related

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 use PHP/HTML as interface and Java/Python as function in background? [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 6 years ago.
Improve this question
I'm thinking about writing a desktop application that the GUI is made with either HTML or PHP, but the functions are run by a separate Java or python code, is there any heads up that I can look into?
There are a couple of possible options:
Run your backend code as an embedded HTTP-server (like Jetty* for Java or Tornado* for Python). If the user starts the application, the backend runs the server and automatically starts the web browser with the URL of your server. This, however, may cause problems with the operating system firewall (running a server on the local machine)
You could also have a look at CEF (chromium embedded framework). It is made for exactly this purpose (running an HTML-Application inside your code). It uses the same codebase as the chromium (and chrome) web browser. It was developed originally for C++, but there is also a Java binding: java-cef
Oh and by the way, PHP is a server-side language. I would not recommend to use it in your scenario (since your backend code is Python or Java).
*I have not enough reputation to add more than two links, so you'll have to google those ones yourself.
You could expose data from Java or Python as JSON via GET request and use PHP to access it. There are multiple libraries for each of these languages both for writing and reading JSON. GET request can take parameters if needed.

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!

When is java used in a Dynamic Web Project? [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 loved the diversity of java ever since my first time using it. With that said I have tried to use it to its fullest. I am in the development of a computer game, android game, and website. Yay me. My problem is that I've been learning html, css, and a little bit of javascript for use in an eclipse dynamic web project. I don't see where or how java plays into the equation. To summarize I am asking for an explanation of where java would be used inside of a dynamic web project and maybe an example.
What I have now: http://192.168.43.194:8080/Pointlight_Productions/homepage.html
Dynamic web project is an Eclipse term, as far I know. When you create a Dynamic Web Project, you're typically telling Eclipse to manage your project as if it were intended as a web application to be deployed on a Servlet container. Eclipse will compile your source and resources and produce a .war file that you deploy in a Servlet container (Tomcat, Glassfish, etc.)
A Servlet container is written in Java. But this is provided. You write Java server code. In other words, you implement a number of Servlet classes that handle requests and generate responses.
For example, you might want to show a customized page for a user in an HTTP web application. Your Servlet would receive an HTTP request containing the name of the user. Your Servlet (or the services it depends on) would look up the name in some database, retrieve all the information for the corresponding user, and generate an HTTP response, possibly HTML, that would display that information.
Reading:
Our Servlet wiki page
How do servlets work? Instantiation, sessions, shared variables and multithreading
Java EE 7 Tutorials

Integrating backend code (Java, Python) with HTML [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 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!

Categories

Resources