Using HttpUnit

First Download Apache from

Configure Apache for Eclipse by following the below steps:



(i)Go to Windows->Preferences->Servers->RunTime Environment.

(ii)Click Add->Apache Tomcat v7.0 and specify Tomcat Installation Directory.

After this start the server as below:

Go to Windows->Show View->Servers.

You will be able to see Tomcat Server.Start this server.

Once done create a new Project as Web Dynamic Project.

Create the below example.jsp

<%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
<!DOCTYPE html PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “”&gt;
<title>I am Example 1</title>
<p>Example 1: Welcome to the example 1.</p>


Now create a new test file


package test;
import com.meterware.httpunit.*;

public class test {

public static void main(String[] args) {


WebConversation wc=new WebConversation();
WebRequest request=new GetMethodWebRequest(“http://localhost:8080/temp/example.jsp&#8221;);
WebResponse response=wc.getResource(request);
System.out.println(“Title of the page is “+response.getTitle());
System.out.println(“Response of the page is “+response.getResponseMessage());
System.out.println(“URL of the page is “+response.getURL());

catch(Exception e)
System.out.println(“Exception is “+e);




Compile and run the file.


You should see the below output:

Title of the page is I am Example 1
Response of the page is OK
URL of the page is http://localhost:8080/temp/example.jsp




About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s