public
String getServerName()
Returns
the host name of the server to which the request was sent.
import java.io.*; import javax.servlet.*; import javax.servlet.annotation.WebServlet; import javax.servlet.http.*; @WebServlet(urlPatterns = {"/GetServerDetails"}) public class GetServerDetails extends HttpServlet { @Override public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException { try(PrintWriter out = res.getWriter()){ String serverName = req.getServerName(); int port = req.getServerPort(); out.println("<html><head><title>Server Details</title>"); out.println("<body><h1>"); out.println("Server Name: " + serverName); out.println("<br />Server Port: " + port); out.println("</h1></body></html>"); } } }
No comments:
Post a Comment