Archive for JSP

JSP – How to get server host name

Monday, April 27th, 2009

Server host name can get from request object of JSP. This method returns the host name of server e.g. localhost or domainName.com in a string.

<%@ page contentType="text/html; charset=iso-8859-1" language="java"  %>
<%
 String hostName=request.getServerName();
%>
<html>
<head>
<title>Server host name in jsp</title>
</head>

<body>
 Host Name of server <%=hostName%>
</body>
</html>