Since Java 5, JAX-RS specification has been announced in order to support building REST web services according to the REST architectural pattern. JAX-RS is a set of interfaces or APIs which provides the building blocks for building REST services in java. Although you can’t build a fully functional RESTful service using these interfaces, there exists a lot of popular frameworks...
It is a common practice that a controller redirects to another resource after processing a request, the resource could be either a view which displays the result of processing or even another controller which needs to do further processing on the request. In this tutorial, we explain the different ways of redirecting requests from servlet to another resource. Basically we...
JSP is mostly used as the view component in any java-based MVC application, its main usage is to present dynamic data processed and generated from server-side controllers like servlet. In this tutorial, we explain the different ways of passing attributes/parameters from servlet to JSP, along with several examples specific for passing data types like: objects, arrays, lists and maps. 1....
In this tutorial we explain the common way of passing data from html to java servlets, we mostly focus on passing form data entered by end-users through pages like: login, sign-up, contact-us .. 1. Pass form fields to servlet Consider the following login.html:
<form name="loginForm" method="GET" action="LoginProcessor">
Username: <input type="text" name="username"/> <br/>
Password: <input type="password" name="password"/> <br/>
<input type="submit" value="Login" />
Users interact with web applications through forms, the “form” element is the common way for asking end-users...
In this tutorial, we provide a step-by-step guide for creating a hello world web application using JSP technology. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create dynamic web project Open eclipse, then select File -> New -> Dynamic Web Project. In the next screen, fill the mandatory fields as above, you are free to choose any...
In this tutorial, we provide a step-by-step guide for creating a hello world web application using Servlet 3.0 technology. Servlet 3.0 supports defining and exposing servlets using annotations, if you still love to define servlets manually, refer to our previous tutorial about creating web applications using servlet 2.5. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create...
In this tutorial, we provide a step-by-step guide for creating a hello world web application using Servlet 2.x technology. Prerequisites: Eclipse IDE (Mars release) Java 1.7 Apache tomcat 7 1. Create dynamic web project Open eclipse, then select File -> New -> Dynamic Web Project. In the next screen, fill the mandatory fields as above, in case you didn’t previously...
Since String is immutable, it is very costly to use it when constructing a dynamic character string due to the fact that a new memory location will be allocated at each assignment or modification. Since its first release, Java supports a mutable class called StringBuffer which constructs dynamic character strings through allocating just 1 memory location, this saves a lot...
Java 7 supports a new statement called try-with-resources which extends the behavior of the traditional try/catch block for the sake of automatic resource management, since Java 7 developers are able to access resources (files, db connections, sockets) inside a try-with-resources block without the need to worry about closing them afterwards, the resource closure is done automatically. 1. Resource management using traditional...