<%@ page import="javax.servlet.ServletContext" %> <% ServletContext context = request.getServletContext(); String serverInfo = context.getServerInfo(); out.print("Server Information: " + serverInfo); %>
import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletContext; @WebServlet("/MyServlet") public class MyServlet extends HttpServlet { private static final Logger logger = Logger.getLogger(MyServlet.class.getName()); protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ServletContext context = request.getServletContext(); String serverInfo = context.getServerInfo(); logger.info("Server Information: " + serverInfo); } }Package Library: The javax.servlet.ServletContext class is part of the Java Servlet API, which is included in the javax.servlet package library.