Blog Archive

JSP find server host name - getServerName()

The HttpServletRequest has method getServerName() to retrieve the server host name. Here is a sample JSP code...


<%@ 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>Get Server name(hostname) in JSP</title>
<link rel="stylesheet" href="/resources/themes/master.css" type="text/css" />
</head>
<body>
<div id="allContent">
<%@include file="/header.jsp"%>

<div id="myContent">
<h1>
        JSP - Get Server HOST name 
</h1></div>    
<div id="myExample">
    Server host name is: <b><%=request.getServerName() %></b>
</div> 

<%@include file="/footer.jsp"%>                                
</div>
</body>
</html>

Tip: You can use the same method inside a Java Servlet 


6 comments :

  1. Minecraft is a game based around a seemingly simple goal. Players must navigate an infinitely expanding world of cubes and collect blocks of various materials. With these materials, players can use the Minecraft crafting system to build nearly anything they can imagine. minecraft hosting

    ReplyDelete
  2. You have shared a nice programming system which can get the server host name, It is good for us to know the server name to playing game on this server. get the high performance Minecraft Server Hosting service at competitive price.

    ReplyDelete