What tech needed to run JSP and Servlets? - java

If I want to build a site with PHP, all I have to do is install the PHP package and make sure mod_php is enabled in my apache web server. Voila! a PHP environment.
Now, if I want to build a site with equivalent Java tech, i.e. JSP and Servlets, What do I have to install?

You need a servlet container, such as Tomcat or Jetty. They are both easy to configure, and there are lots of tutorials available online.

You only have to install Java (usually already done) and a servlet container like Tomcat.

Netbeans locally includes all startconfig and sample projects needed and you can deploy to gae or eatj. It's complicated and worth the effort. You can go with gae or custom your own with jetty, tomcat, jboss, websphere or glassfish. 512 RAM was minimal after trying with 256 which permgened. You might try with 256. I recommend avoid EJB and custom tags and keep web archives instead of enterprise archives for small to medium projects.

You will need a Java Web Container (Tomcat is a good starting point) plus needing to tell your Apache frontend how to reach the web container from the outside.
Note, most modern Java Web Containers can perform well enough to not need a frontend Apache server.

You need to install the Java Environment, where a web server, The code which does the appropriate functions.
You will be using the jsp for the view part
Servlets for the Basic modal part, where you will write the business logic
and Web.xml, is the deployment descriptor where you will tell the server aabout the servlets and jsp and how the control of the flow will be defined

Related

what is the role of apache server in java swing application (3 tier)?

I have made a Java Swing application, in the GUI the user can select the type of element and choose a date then the element's informations will be shown on a JTable.i used easyPHP to create the DB.
so what is the role of apache server in this case!
can i consider it like an application server ?
A Java swing application (AFAIK out of the box, for alternatives see below) is not available over HTTP/S (and is therefore not classified as a web application) and Apache is a web server (with features such as proxy, TLS terminator etc.). Therefore there would be no need for a web server such as Apache to front your Swing application.
Apache web server is not an application server for a Swing application per se. Although it can run applications in different programming languages such as php through loading of modules. It however does not run Java web applications.
An application server in a Java perspective would be Tomcat, Glassfish, JBoss, WebLogic etc. An application server hosts an application and could provide a set of services such as Naming, HTTP processing and so on.
Perhaps you are referring to Apache Tomcat instead of Apache Web Server. If so, you would be right on the mark as that is an application server for Java web applications.
If you would like to make your application available through HTTP and enjoy the myriad and expansive benefits of an application server, I would recommend you to rethink on using Swing and utilize a technology built over Java Servlets such as JSPs, Spring MVC and so on.
If you would still like to make the Swing application available through a web server (through HTTP/S) there are some solutions out there but I have not tried any of those. Please do a search on "Swing available on HTTP" in that case. I have also provided a link as well.
You can read up on Application Servers on this wiki link.
You can read up on an HTTP end point for a Swing application here.
This Apache is not used in your application. You installed easyPHP so Apache comes with that to provide PHP programming environment.
Moreover Apache is a web server. So any web based application can be deploy here. PHP is a web programming language sot it requires Apache or any other web server.
But your application is standalone developed with JAVA SWING. So you can stop Apache server and check everything is running fine or not.

Running portable web services application server

I need portable container for running web services as server. JSON as a response. The server application must be able to start up using .bat script under Windows. Machine running the server must have only Java Runtime Enviroment installed, no other stuff required.
Axis2 on top of Tomcat do not seem like simple portable web server. What are the other alternatives?
UPDATE:
How come no one offered?
com.sun.net.httpserver.HttpServer;
and
com.sun.jersey.api.container.httpserver.HttpServerFactory;
Jetty is a good option.
Another very lightweight option is fluent-http.
I'm not that familiar with Axis2, but as far as I know you can use embedded tomcat to achieve this with whichever frameworks you please.
Take a look at the tomcat maven plugin which I believe will even generate your application as a jar containing embedded tomcat in the latest version.

Standalone Java application with HTML front end

I want to develop a standalone java application, with web browser as front end. This application will run locally and won't be making any remote server calls. I'm essentially using java, as web-browser cannot perform file operations.
I want this application to be portable: no need of installation. Just copying a folder should be enough. I want to know how it can be done, how will javascript communicate with java code.
In continuation of #Quentin's answer.
Yes, you need web server.
There are 2 principal architectures:
Create stand alone application with embedded web server
Create ordinary web application and run it on proprietary web server.
IMHO I think that the second approach is better, however it strongly depend on your application functionality.
You can take jetty or grizzly as a web container. Both can run as in embedded or stand alone modes. You are welcome to share other details of your application with the community if you need concrete advises concerning to the design of your application.
The application would need to implement an HTTP server. Then all communication would be done over HTTP.
Write a small web application as you need and Deploy it using Jetty. Jetty is a pure Java-based HTTP server and Java Servlet container. You can use it by embedded mode also.
Deployment is so easy if you use Jetty-Runner
java -jar jetty-runner.jar my.war
You don't need a local web server. Take JavaFX (embedded webkit) and implement a URL protocol handler for say "myprotocol". Then you can access it from the browser using something myprotocol://xxx.yyy.zzz

Deploying Netbeans REST webservice on Apache server

I'm studying webservices in differents languages and now, I'm stuck on Netbeans one.
I easily create a "RESTful web service with Database" on localhost.
So, I use a MySQL (Connector/J driver) connection with GlassFish server.
My question is : what's the difference between an Apache server and a GlassFish one ?
Indeed, I aim to deploy this webservice on Apache server but I have no idea to do it.
Is someone have tips or ways to help me ?
Thanks a lot !
I'm assuming you followed this tutorial.
If you mean good old trusty Apache httpd, you won't be able to deploy the project you created to that server, what you create is a Java Enterprise application (and more specifically a WAR, a Webapplication ARchive), and you will need a server capable of deploying that type of applications - like of course Glassfish, but also Apache Tomcat, jetty or any of the Java Enterprise Edition servers
Still assuming that you're talking about Apache httpd, that one and Glassfish are entirely different beasts that serve different purposes, Glassfish is indeed capable of serving up content over http but it contains much more functionality than that, see the above Wikipedia link on Java EE for more links and pointers.
EDIT: you cannot run a servlet container like Tomcat or a Java EE server like GlassFish "inside" an Apache server like you would run php "inside" Apache with mod_php, but it's quite easy to run them alongside each other, where the Apache httpd server is the one that faces outward and basically forwards calls to the backend Java server. There are several techniques to achieve this result, the most popular is probably using mod_jk as explained here for Tomcat and here for Glassfish. Alternatively you could setup mod_proxy, a comparison of these two scenarios here on SO.
Anyways, it's not always necessary to front a Tomcat or Glassfish with an Apache but it may be needed e.g. if the website is serving hybrid content partially written in php or another apache-hosted scripting language or useful to avoid using the servlet container to serve up massive quantities of static content, often not their strongest point. For many applications it's perfectly OK to have a Tomcat or a Glassfish serve up all content avoiding the extra complications introduced by mod_proxy or mod_jk and the dual management of both servers.
open server.xml file in conf folder of apache tomcat. And check for line
Here you can see port =5051 means apache tomcat is configured in port 5051
Open we browser and type http://localhost:5051
Then click "Tomcat manager"
Enter your usename and password
In the next screen you can see section "WAR file to deploy". Select your web service war file and click deploy

Servlet container; What is it and do I need it in my case?

I have just ordered a VPS from my provider.
I have some Q however...
My website uses Solr, which requires the following according to their website:
"Solr requires Java 1.5 and an Application server (such as Tomcat) which supports the Servlet 2.4 standard"
I also need php 5, MySql, and the usual javascript etc...
The OS is Ubuntu 9.10
1- So what do I need to install then?
2- What is a servlet container?
3- The solr I have downloaded came with Jetty. Is Jetty a Servlet container?
Thanks
3- The solr I have downloaded came
with Jetty. Is Jetty a Servlet
container?
Yes, Jetty is a Web server and Servlet container. A servlet container is a web server that interacts with servlets, and you need one of those to host your servlets, execute them, etc.
An application server typically hosts many other facilities, such as security, authentication, Java Mail, EJB container, and many others.
PHP: Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed for web development to produce dynamic web pages.
PHP 5 included new features such as improved support for object-oriented programming, the PHP Data Objects extension (which defines a lightweight and consistent interface for accessing databases), and numerous performance enhancements.
Servlets are Java programming language objects that dynamically process requests and construct responses. Jetty is the simplest/smallest servlet container that could be run easily in a cross platform way. That does not imply that Solr runs better under Jetty, or that Jetty is only good enough for demos, it's just that Jetty makes demo setup easier.
Users should decide for themselves which Servlet Container they consider the easiest/best for their use cases based on their needs/experience. For high traffic scenarios, investing time for tuning the servlet container can often make a big difference.
A Servlet container is basically a web server for Java Servlets and JSP pages.
Tomcast and Jetty are both Servlet containers.
In the phrase you quoted, it is using the phrase "Application server" interchangeably with "Servlet container". While Solr may only require a Servlet container, it shouldn't use the terms interchangeably.
The Servlet container is only part of a J2EE application server. Some other application servers (that also include Servlet containers) are JBoss and Apache Geronimo; Geronimo uses either Tomcat or Jetty depending on which set you install.
If you also need PHP, a Servlet Container won't be enough... you'll also need a normal webserver.
Installing the libapache2-mod-php5 module from the Ubuntu repository should install both PHP5 and Apache 2.2 for you. To install MySQL, install the mysql-server and php5-mysql packages.
Assuming you only have command-line access, installing packages on Ubuntu is done using the aptitude or apt-get programs; aptitude is preferred.
Before you install new programs, you should always run aptitude update, which updates the local index of which programs are available. Afterwards, you can upgrade existing packages with aptitude safe-upgrade and install new packages with aptitude install <packagename> (without the <>)
Ubuntu is usually pretty good about keeping the available package list up to date, and will periodically tell you on login that some packages have available upgrades. Since upgrades are almost always security updates, it is a good idea to check for them.
I also need php 5, MySql, and the usual javascript etc... The OS is Ubuntu 9.10
1- So what do I need to install then?
Use Apache HTTPD server for PHP, use Apache Tomcat for JSP/Servlet, use mod_jk to let HTTPD play proxy for Tomcat so that you can run PHP and JSP at one same site.
Since JavaScript is a client side language, you don't need to worry about it at the server side.
2- What is a servlet container?
A webserver with a JSP/Servlet API implementation. An application server is usually more than that. JSP/Servlet is only a little part of the huge Java EE API. A fullfledged application server implements pretty much all of Java EE API.
3- The solr I have downloaded came with Jetty. Is Jetty a Servlet container?
Yes, it is. It however doesn't support PHP. You need Apache HTTPD for PHP. However I am not aware of ways to connect Jetty with HTTPD.

Categories

Resources