Server snoop

Server snoop


Posted in : Java Posted on : June 13, 2011 at 6:28 PM Comments : [ 0 ]

In this section we will discuss how can a server information be displayed in Java Servlet.

Server snoop

In this section we will discuss how can a server information be displayed in Java Servlet.

Snooping the server is an act to find the information of a server i.e. what is its name, port number, protocol etc as your requirement.

Example :

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ServerSnoop extends HttpServlet {
String servername, serverprotocol, serverscheme;
int serverport;

public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {

servername = req.getServerName();// Show the server name.
serverport = req.getServerPort();// show the server port no.
serverprotocol = req.getProtocol();// Show the protocols name and
// version used by you.
serverscheme = req.getScheme();// show the scheme name used to make this
// request.
PrintWriter pw = res.getWriter();
pw.println("<html><head>");
pw.println("<title>Server Information</title></head>");
pw.println("<body bgcolor=#ff00ff>Name of Server is : " + servername
+ "<br>");
pw.println("Port number of a Server " + servername + " is "
+ serverport + "<br>");
pw.println("The server prottcol is " + serverprotocol + "<br>");
pw.println("Name of Scheme that is used to make this request : "
+ serverscheme);
pw.println("</body></html>");
}
}

The xml file need to be edit as

<servlet>
<servlet-name>bipul3</servlet-name>
<servlet-class>ServerSnoop</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>bipul3</servlet-name>
<url-pattern>/ServerSnoop</url-pattern>
</servlet-mapping>

Output :

When you will execute this code at server the output will be showing as below.

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics