Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Tuesday, 9 July 2013

Get IP address of an URL using Java


How to get an IP address of a URL using Java

It is often required to know the IP address of a website while building some applications, and it is very simple to know the IP of any URL using the Java. Java provides a class called InetAddress that can be used to get the IP.

Here is an example that shows that how we can get the IP address of an URL:

import java.net.InetAddress;
import java.net.UnknownHostException;


public class KnowIP {

 public static void main(String[] args) throws UnknownHostException {
  
  InetAddress address=InetAddress.getByName("www.google.com");
   
  String ipAddress=address.getHostAddress();
  
  System.out.println(ipAddress);
 }
}
My Daawat

Wednesday, 29 May 2013

How to Get CheckBox values in JSP


Example to get checkbox value:

The example shows how to get the multiple checkbox values from one page to another.

 To get the checkbox values we take the name of all the checkboxs same.
 Here we are taking name as hobbies, the values for all these will be different.

First Page:



Select Your Choice Here:-

Now at next page where we are getting these values we use request object's method getParameterValues(). This method take a string argument which is the name of the checkbox. at the first page. It returns an array of String, which contains the values of the checkboxes which are checked.

Second Page:

Your Hobbies are:-

<% String hobbies[] = request.getParameterValues("hobbies"); for (String hobby : hobbies) { out.println("" + hobby + ""); } %>

Start and Stop Process in windows using Java


Here is a simple Example to start and stop windows process using Java Program

To start a process we get a RunTime object through Runtime class method getRuntime().

Now we invoke the exec() method through this object that returns an object of started process.

This object can be used to stop the process by calling destroy() method of it.
import java.io.IOException;
public class StartAndStopProcess{

    public static void main(String[] args) throws IOException, InterruptedException {
   
   
        Runtime run = Runtime.getRuntime();
       
        //start process
        Process pro = run.exec("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
   
        Thread.sleep(5000);
       
        //stop process
        pro.destroy();
    }

   
}
My Daawat