Category: J2EE

Download file from a Web Application using Servlet

This tutorial shows how to download a file from a web application using Servlet. A typical task in most web applications is to download files stored at the server side to the client’s machine, here below we provide the common way of doing this with Servlet. 1- Download File Servlet Below is an example of a typical Servlet which downloads files...

Disable save password prompt on login forms using CSS

Browsers automatically prompt users to save their password after login. In fact, this functionality provides a big advantage for allowing the user to login afterwards without reentering his credentials again. However, it also has its disadvantages and some people considers it as a security leak since anyone can view your saved passwords using the browser settings. In this tutorial, we...

How to handle HTTP 403 forbidden error in Java

Sometimes when trying to consume a web service from a java client, you get a 403 forbidden HTTP response code, even though the service is accessible normally from web browsers. The HTTP 403 forbidden error doesn’t necessarily occur due to missing authentication attributes, some web services would only authorize web browsers or some specific clients to access them, while they...

How to exclude a URL from a Filter

By default, filters doesn’t support excluding a specific URL pattern, whenever you define a URL pattern for a filter then any request matching this pattern is handled by the filter without exceptions. The simplest way for excluding URLs from a filter is to map your filter to a very specific pattern. This is feasible when done in early development stages,...

Deploy JAX-WS service on tomcat

This tutorial provides a step-by-step guide on how to build and deploy JAX-WS web service on Tomcat. Throughout this tutorial, we create a very simple SOAP web service and finally deploy it on Tomcat application server. Prerequisites: Eclipse IDE (Neon release) Java 1.8 Apache Tomcat 8 1. Create Maven web project Create a maven web project using this tutorial and name your...

Build SOAP service with JAX-WS

JAX-WS is an API used for building and consuming XML web services in Java, it was first released in Java EE5. In this tutorial, we provide a step-by-step guide on how to build SOAP web service with JAX-WS and finally publishing it using Endpoint built-in class. Prerequisites: Eclipse IDE (Neon release) Java 1.8 1. Create standalone Java project Open eclipse,...

Build REST web service using Spring

This tutorial provides a step-by-step guide on how to build REST web service using Spring framework. Prerequisites: Eclipse IDE (Mars release) Java 1.8 Apache tomcat 8  1. Create Maven web project Create a maven web project using this tutorial and name your project as SpringRestService. The structure of the generated project looks like the following: 2. Add Spring dependencies After creating...

Building REST web service using RESTEasy

RESTEasy is yet another popular framework which implements JAX-RS specification and is widely used for building REST web services in java. In this tutorial, we provide a step-by-step guide for building a REST web service using RESTEasy framework, we provide different ways to configure RESTEasy with both Servlet 3.0 and Servlet 2.0. If you’re interested in Jersey, check this tutorial. Prerequisites: Eclipse IDE...

Building REST web service using Jersey

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...

forward() vs sendRedirect() vs include()

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...