Creating a Servlet from an Existing Java Project

I have a Java Swing project for my class. I would like to host it on my website so people can use it. However, I'm not sure if there is a way to turn it into a servlet. Or do I need to know JavaScript? I'm confused. Is there a way to make my application swing into a servlet automatically?

+2


a source to share


4 answers


Servlets are commonly used in Java to create dynamic web applications and web services.

If the goal is to port your Swing application to something that can be used in a web browser, perhaps this approach would either:



To run Java applications with a graphical user interface that runs on a client machine, the approach will not use a servlet, as it will require a server that runs a web container such as Tomcat or GlassFish.

+2


a source


Instead of JFrame, you should use an applet that is similar and should embed zhis into your web page.



Have a look at Java Webstart too!

+1


a source


If your application is a large commercial one, you can use Ajaxswing for (almost) automatic conversion.

Otherwise, you must rewrite it. If it was written well, that is, with a separation between user interface and business logic, you only need to write the interface and reuse the business logic. If not, here you learned how to structure your code.

+1


a source


If you just want to provide an application as is on a web page where people can click it to launch it, you need Java Web Start technology.

This will require you to learn how to write a JNLP file that describes which jars your application needs and is bundled with the rest of the files.

If your application needs to use resources outside the installed sandbox, you either need to request them explicitly using Web Start methods, or tell a JNLP script that your application needs unrestricted machine access and then you must sign the jars.

You can also just create a unified jar that says inside the manifest what the main class is, then allow users to download it and then double click on the locally saved file to run it. This will be what I would recommend at the moment as it is the simplest approach.

+1


a source







All Articles