Friday, 25 September 2015

How to get client ip address in java servlet

HTTPServletRequest Object has a method called servletRequest.getRemoteAddr(). This method can be used to get the ip address of the client.
    String ipAddress = request.getRemoteAddr();  

Friday, 12 June 2015

Utility class to read excel file in java and return rows as list

In this tutorial we gonna make a utility class that accepts file as argument ( .xlsx file ), parse it and return rows as List. You can make use of this class in your project to read excel file and get the contents. For this first we need Apache POI. Apache POI is the pure Java API for reading and writing Excel files in both formats XLS (Excel 2003 and earlier) and XLSX (Excel 2007 and later).

Thursday, 9 October 2014

Java program to execute shell scripts on remote server

If you want to execute shell scripts on remote server and get output with the help of your java program then you are at right place. In this tutorial we will be using Java secure channel ( Jsch ) to log on to remote server, execute the shell script and capture the output. JSch is a pure Java implementation of SSH2. ( download jSch ).

Call a method just before a session expires

In this tutorial we gonna learn that how to call a specific method when a session is going to be destroyed or invalidated by the application container. First of all we need to know why we are doing this. Well it may have many applications but typically we use it for updating user counts, releasing resources etc. We could use HttpSessionListener and do the job in sessionDestroyed() method.

Life cycle of the servlet

A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. ( more reference ).

Tuesday, 30 September 2014

How to detect width of text inside text box

In this tutorial we are going to see how to calculate the width of text inside the text box. First of all we need to know why we are trying to achieve this. This is useful when you want to position some text suggestion just beneath the user cursor inside the text box. The image given below will provide better understanding of the scenario.

Wednesday, 20 August 2014

Javascript event capturing and bubbling

JavaScript uses two models for event delegation, capturing and bubbling. If you go back in old days, Netscape said that event on parent will take place first and Microsoft said that event on target element will take first. The W3C model combines both capturing and bubbling by saying that an event first makes its way downwards visiting captures i.e parent to target child and then bubbles back visiting non captures. Lets explore further