How to use a filter in JSP?

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
Following example shows how to print the client's IP address and the current date time, each time it would access any JSP file. This example will give you a basic understanding of the JSP Filter, but you can write more sophisticated filter applications using the same concept −// Import required java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; // Implements Filter class public class LogFilter implements Filter {    public void init(FilterConfig config) throws ServletException {       // Get init parameter       String testParam = config.getInitParameter("test-param");       //Print the init parameter ... Read More

How to use contains () in Android text view?

Anvi Jain
Updated on 30-Jul-2019 22:30:25
This example demonstrate about How to use contains () in Android text view.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             In the above code, we have taken name as Edit text, when user click on button it will take data and compare with tutorialspoint string.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; ... Read More

MonthDay compareTo() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25
Two MonthDay objects can be compared using the compareTo() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be compared.If the first MonthDay object is greater than the second MonthDay object it returns a positive number, if the first MonthDay object is lesser than the second MonthDay object it returns a negative number and if both the MonthDay objects are equal it returns zero.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       MonthDay md1 = ... Read More

Duration minusHours() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25
An immutable copy of a duration where some hours are removed from it can be obtained using the minusHours() method in the Duration class in Java. This method requires a single parameter i.e. the number of hours to be subtracted and it returns the duration with the subtracted hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       Duration d = Duration.ofHours(6);       System.out.println("The duration is: " + d);       System.out.println("A copy with 4 hours removed from the duration is: ... Read More

How to loop thrugh a stored procedure in MySQL?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
Let us see how to loop through a stored procedure in MySQLmysql> DELIMITER // mysql> CREATE PROCEDURE do_WhileDemo(LastValue INT)    -> BEGIN       -> SET @loop = 0;       -> REPEAT          -> SET @loop= @loop+ 1;          -> select @loop;          -> UNTIL @loop >LastValue       -> END REPEAT;    -> END // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;Now call the stored procedure with the help of CALL command.The query is as followsmysql> call do_WhileDemo(10);The following is the output+-------+ | ... Read More

Ignoring the year in MySQL Query with date range?

Samual Sam
Updated on 30-Jul-2019 22:30:25
To ignore the year with date range, use the DATE_FORMAT() with the between clause. Let us first create a demo table. The query to create a table is as follows −mysql> create table igonreYearDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ShippingDate date    -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into igonreYearDemo(ShippingDate) values('2016-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into igonreYearDemo(ShippingDate) values('2018-01-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

Reading and writing binary file in C/C++

Samual Sam
Updated on 30-Jul-2019 22:30:25
WritingTo write a binary file in C++ use write method. It is used to write a given number of bytes on the given stream, starting at the position of the "put" pointer. The file is extended if the put pointer is currently at the end of the file. If this pointer points into the middle of the file, characters in the file are overwritten with the new data.If any error has occurred during writing in the file, the stream is placed in an error state.Syntax of write methodostream& write(const char*, int);ReadingTo read a binary file in C++ use read method. ... Read More

Callbacks in C

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25
The callback is basically any executable code that is passed as an argument to other code, that is expected to call back or execute the argument at a given time. We can define it in other words like this: If the reference of a function is passed to another function argument for calling, then it is called the callback function.In C we have to use a function pointer to call the callback function. The following code is showing how the callback function is doing its task.Example Code#include void my_function() {    printf("This is a normal function."); } void my_callback_function(void (*ptr)()) ... Read More

Develop a WiFi Scanner for Android

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25
This example demonstrate about How to develop a WiFi Scanner for AndroidStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.Manifest; import android.content.Context; import android.content.IntentFilter; import android.content.pm.PackageManager; import android.net.wifi.WifiManager; import android.os.Build; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ListView; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    private ... Read More

Java Program to create a TreeSet with custom Comparator

Krantik Chavan
Updated on 30-Jul-2019 22:30:25
To create a TreeSet with custom comparator, let us first create a an Integer array and set it to TreeSetInteger arr[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; Set set = new TreeSet(Collections.reverseOrder());Above, we have used the Comparator with reverseOrder(), which returns a comparator that imposes the reverse of the natural ordering.Exampleimport java.util.Collections; import java.util.Set; import java.util.TreeSet; public class Demo {    public static void main(String args[]) throws Exception {       Integer arr[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };       Set set = ... Read More
Advertisements