Servlet Login and Logout Using HttpSession Example

Here you will get servlet login and logout example using HttpSession. There are various ways to maintain session but here I will use HttpSession class. In this example we have a index.html page where a login form is displayed. When user enters login details and submits the form the request is sent to LoginServlet. If the details are correct then user is redirected to HomeServlet otherwise redirected to index.html. LogoutServlet invalidates the sessions to logout the user and redirect to index.html. If anyone tries

Read more

Servlet Registration Form with MySQL Database Example

Here you will get servlet registration form with mysql database example. This simple registration form include three fields, full name, email and password. If you want you can add more fields. Servlet Registration Form with MySQL Database Example MySQL Database As here we are using mysql database so create a database with name db. Now create a table with name user having three fields fname, email and pass of varchar type. Java Project Create a dynamic web project and add following

Read more

Download File From Server Using Servlet Example

Here you will get example to download file from server using servlet. The file can be of any type like image, pdf, video, music, etc. How it works? First set the content type to application/octet-stream. Now set the Content-Disposition header to attachment;filename=fileLocation. Read file from the source location using FileInputStream and write to ServletOutputStream to send as response. Also Read: Upload File to Server Using Servlet Example Download File From Server Using Servlet Example WebContent/index.html This page contains a download link.

src/com/DownloadServlet.java

Read more

Upload File to Server Using Servlet Example

Here you will get example to upload file to server using servlet. File uploading is a very common and important feature of any website. In servlet it can be done in many ways. But in this tutorial I am sharing the two most commonly used methods. Also Read: Download File From Server Using Servlet Example How to Upload File to Server Using Servlet? Method 1: Servlet 3.0 If you are using Servlet 3.0 version then it provides option for uploading files

Read more

Save and Retrieve Image from MySQL Database Using Servlet and JSP

Here you will learn how to save and retrieve image from mysql database using servlet and jsp. This method will work with Servlet 3.0 and MySQL 5.5 and higher versions. Also Read: How to Connect Java (JDBC) with MySQL or Oracle Database Save and Retrieve Image from MySQL Database Using Servlet and JSP Database Create a table in mysql database with following schema. Database Name: test Table Name: data Here I have used MEDIUMBLOB datatype to store image in database. It

Read more