Learn how to develop java web application

Learning on how to develop web application today is very important to IT professionals. Web applications are powerful because it is designed as client-server architecture and it is very popular today. What is good in web application is that it easy to deploy what you need is to upload it on a webserver and you do not need to distribute in on the client computer using a CD or installer. The client only need a web browser and internet connection to access the web application. Also what I like most in a web application is that it does not bounded to a single Operating System, it can run on any OS and that makes web application a technology neutral. In my case I use Java servlet, JSP, HTML5, JavaScript and CSS in developing web application.

Today there are many threats in security online and the reason I develop web application using Java because it is secured and Java is good on catering multi user having simultaneous connections. Using Java servlet web developer can create a dynamic and interactive website. It can store and retrieve data to database. Some of the web application that can be creates using Java servlet are enrollment system, online reservation, online registration and other interactive and web applications.

I will discuss how I start to create a simple Java servlet program and what are the things needed as well as the steps. To create Java servlet you need to install Java in your computer, and also web server like tomcat. Below is my simple Java Servlet that display a string in a browser.

package foldername;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DisplayString extends HttpServlet{
  public void doGet(HttpServletRequest request,
  HttpServletResponse response)
  throws ServletException,IOException{
  response.setContentType("text/html");
  PrintWriter pw = response.getWriter();
  pw.println("<html>");
  pw.println("<head><title>Java Servlet that will display a string</title></head>");
  pw.println("<body>");
  pw.println("<h1>Hello Java Servlet</h1>");
  pw.println("</body>");
  pw.println("</html>");
  }
}

The explanation of code above is that the package is a java keyword and foldername is a folder that your java class is located, in this example the class name should be DisplayString because in java, the name of the class should be the same as the filename. Next, import java.io.*; , import javax.servlet.*;, import javax.servlet.http.*; are the java pacakage that need to be imported in order for our java program to run. The public class DisplayString extends HttpServlet means that you create a class with a name DisplayString and it is a public claas and it can be access by other class. The extends HttpServlet means that you extended the methods and functionality of the HttpServlet class to the class that you created, in this case the DisplayString.

The public void doGet(HttpServletRequest request,  HttpServletResponse response) means doGet is a method with two parameters the HttpServletRequest request and  HttpServletResponse response. Since the architecture of Java servlet is a client-server, request is an object of type HttpServletRequest and it is the client who will request a resources to a server and response is an object of type HttpServletResponse for the server that will response to the resources requested or sent by the client. The response of a server is in the form of text or html.