Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Display the server port and protocol number in the browser in scrolling from right to left format.

Here we have developed a program which will display the server and port number of the browser in which you are running your java code.


Java Program - 

index.html - 

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <form method ="post" action="info">
            <input type ="submit" value="GetClientInfo">
        </form>
        
    </body>
</html>


web.xml - 

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
    <servlet>
        <servlet-name>InfoServlet</servlet-name>
        <servlet-class>ClientInfo</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>InfoServlet</servlet-name>
        <url-pattern>/info</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>


ClientInfo.java - 

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

public class ClientInfo extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html;charset=UTF=8");
        PrintWriter out = response.getWriter();
        try{
            int serverPortNumber = request.getServerPort();
            out.println("<h3> Server Port Number >"+serverPortNumber+"</h3>");
            String protocol = request.getProtocol();
            out.println("<h3>Protocol >"+protocol+"</h3>");
        }
        finally
        {
            out.close();
        }
    }
    
}


Output - 





Post a Comment

0 Comments

Ad Code

Responsive Advertisement