JSP Server Snoop

JSP Server Snoop


Posted in : Java Posted on : May 15, 2012 at 7:04 PM Comments : [ 0 ]

In this tutorial you will learn about how to get information of a server.

JSP Server Snoop

In this tutorial you will learn about how to get information of a server.

Server snooping is an act of finding the server's informations i.e the name of a server, server's port number, server's protocol it uses, etc.

Example :

In the example given below will demonstrate you about how to get the information of a server, In this example I have created a JSP page where I have used the methods of ServletRequest interface to get the information of a server. To use these methods in JSP page I have used the scriptlets and the implicit request object.

Methods used in this example are as follows :

1. getServerName()

Syntax :

java.lang.String getServerName()

This method returns the host name of server the request was sent.

2. getServerPort()

Syntax :

int getServerPort()

This method returns the port number the request was sent.

3. getProtocol()

Syntax :

java.lang.String getProtocol()

This method returns the name and version of the protocol.

4. getScheme()

Syntax :

java.lang.String getScheme()

This method returns the name of the scheme that is used for sending the request. such as : http, https, ftp etc.

5. getRemotePort()

Syntax :

int getRemotePort()

This method returns client's source protocol.

6. getRemoteHost()

Syntax :

java.lang.String getRemoteHost()

This method returns the client's name or the last proxy that sent the request.

serverSnoop.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JSP Server Snoop</title>
</head>
<body>
<table>
<tr>
<td>Server Name = </td> <td><%=request.getServerName() %></td>
</tr>
<tr>
<td>Server Port = </td> <td><%=request.getServerPort() %></td>
</tr>
<tr>
<td>Server Protocol =</td> <td><%= request.getProtocol() %></td>
</tr>
<tr>
<td>Server Scheme = </td> <td><%=request.getScheme() %></td>
</tr>
<tr>
<td>Remote Port = </td> <td> <%=request.getRemotePort() %></td>
</tr>
<tr>
<td>Remote Host = </td> <td> <%=request.getRemoteHost() %></td>
</tr>

</table>
</body>
</html>

Output :

When you will execute the above JSP page you will get the output as follows :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics