Home » Enterprise Java » servlet

servlet

Java Servlet File Upload Example

In this example, we will see how to use servlet to upload a file. We will be just uploading the file to a server folder. As a part of this example, we will create an HTML form that lets us choose a file in your local file system. The file will be uploaded to the server. We will use Eclipse ...

Read More »

JDBC Servlet Example

In this example, we will see how to make use of JDBC from a servlet to access database and read data from table. We will use MySQL as the database and MySQL Workbench as the client for database to prepare the data. However this example does not cover installation of MySQL and MySQL Workbench. We will be using Eclipse as ...

Read More »

Java Servlet Context Listener Example

In this tutorial, I will be demonstrating a simple example of how to use ServletContextListener to make some global initializations and configurations. We will be using WildFly application server and Eclipse to demonstrate the examples in this post. None database is required to run this example. 1. Introduction ServletContext is a configuration object which is created when application server starts and ...

Read More »

Java Servlet Authentication Example

In this example, I will explain how to perform authentication using a servlet running on WildFly application server and Eclipse. We will not be using any database to store user credentials. Table Of Contents 1. Introduction 2. Configure WildFly in Eclipse 3. Create New Dynamic Web Project 4. Create Authentication Helper Class 5. Home Servlet 6. Application Servlet 7. Login Html 8. ...

Read More »

Servlet Lifecycle Example

In this example we are going to examine what is the servlet lifecycle and how it all works out in the servlet container. Basically, by “lifecycle”, we actually mean the whole process of creating and initializing the servlet, using it and destroying it when it is no longer needed. In the GenericServlet abstract class (which is extended by all the ...

Read More »

Get client’s address and hostname in Servlet

In this example we are going to see how to get client’s address and hostname in a Servlet. Java offers a very convenient way to handle client and server information such as hostname ip address etc. Getting a client’s address and hostname requires that you: Get clients ip adfress using HttpServletRequest.getRemoteAddr(). Get clients hostname using HttpServletRequest.getRemoteHost().     Take a ...

Read More »

Get all Init Parameters in Servlet

With tutorial we shall show you how to get all Init Parameters in Servlet. Using init parameters you can specify servelar inportant aspects of your servlets that are going to be handled during requests service. In order to do that you should: Create public void init() function on your servlet. Call getServletConfig().getInitParameterNames() Use put(initParamName, initParamValue) to put parameters in your ...

Read More »

Get/Set init Parameters in Servlet

In this example we are going to see how to get/set init parameters in a Servelt.Using init parameters you can specify servelar inportant aspects of your servlets that are going to be handled during requests service. In short, to get/set init Parameters in Servlet you should: Create public void init() function on your servlet. Call getServletConfig().getInitParameterNames() Use put(initParamName, initParamValue) to ...

Read More »

Get all Request Parameters in Servlet

With this tutorial we shall show you how to get all requests parameters in a Java Servlet. This the most basic step you have to consider when developing a Servelt application because HTTP is based mostly on parameters exchange. Basically in order to get all Request Parameters in Servlet, one should take the following steps: Create a handleRequest method so ...

Read More »

Get Request Parameter in Servlet

With this tutorial we shall show you how to get request parameter in a Java Servlet. This the most basic step you have to consider when developing a Servelt application because HTTP is based mostly on parameters exchange. You will find this example particularly useful when you want to get the value of known parameter. Basically in order to get ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns