By: aathishankaran Emailed: 1674 times Printed: 2154 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing


             The HttpClient class does the real network communication. It simply sends the designated request line and request headers to the Web server, then reads the lines that come back one at a time, placing them into a TextArea until either the server closes the connection or the HttpClient is interrupted by means of the isInterrupted flag.

String portString = portField.getTextField().getText();

if (portString.length() == 0) {

report("Missing port number");



try {

port = Integer.parseInt(portString);

} catch(NumberFormatException nfe) {

report("Illegal port number: " + portString);



requestLine =


if (requestLine.length() == 0) {

report("Missing request line");






private void report(String s) {



private void getRequestHeaders() {

for(int i=0; i<requestHeaders.length; i++)

requestHeaders[i] = null;

int headerNum = 0;

String header =


StringTokenizer tok =

new StringTokenizer(header, "\r\n");

while (tok.hasMoreTokens())

requestHeaders[headerNum++] = tok.nextToken();



import java.awt.*;




public class HttpClient extends NetworkClient {

private String requestLine;

private String[] requestHeaders;

private TextArea outputArea;

private Interruptible app;

public HttpClient(String host, int port,

String requestLine, String[] requestHeaders,

TextArea outputArea, Interruptible app) {

super(host, port);

this.requestLine = requestLine;

this.requestHeaders = requestHeaders;

this.outputArea = outputArea; = app;

if (checkHost(host))



protected void handleConnection(Socket uriSocket)

throws IOException {

try {

PrintWriter out = SocketUtil.getWriter(uriSocket);

BufferedReader in = SocketUtil.getReader(uriSocket);



for(int i=0; i<requestHeaders.length; i++) {

if (requestHeaders[i] == null)






String line;

while ((line = in.readLine()) != null &&


outputArea.append(line + "\n");

if (app.isInterrupted())

outputArea.append("---- Download Interrupted ----");

} catch(Exception e) {

outputArea.setText("Error: " + e);



JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
What are the different scopes in JSP?
JSP Example to connect to MS SQL database and retrieve records
Sending Email using JSP
JSP CheckBox Example
JSP Program for display Date
Comparison operators in JSP
Arithmetic Evaluation Using the Expression Language in JSP
Syntax For JSP Declaratives
Tags using in jsp
Basic Servlet Structure
Calling JSP from a batch file
Using a DataSource from WebLogic in a JSP
IIS and Tomcat - how to configure to work together
Uploading a file to a server using JSP
JSP Alert Example
Most Emailed Articles (in JSP)
Textarea Object
Click to Activate and Use this control
The Servlet Life Cycle
A JSP page that gets properties from a bean
The JSP Program running first Time.
Embedding java codes in jsp sciptlets
Debugging Servlets
Document Object
Password Object
What is JSP?
A Servlet That Generates HTML
The Advantages of JSP
Retrieving a Portion of a String
Working with Status Bar Messages Connection refused: connect