您可以在 JSP 中尝试下一个:
<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tomcat Version</title>
</head>
<body>
<h2>Tomcat Version</h2>
<pre><%=pageContext.getServletContext().getServerInfo()%></pre>
<h2>Servlet Version</h2>
<pre><%=pageContext.getServletContext().getMajorVersion()%>.<%=pageContext.getServletContext().getMinorVersion()%></pre>
</body>
</html>
抱歉,不再推荐使用 scriptlet。使用 JSTL 更好:
<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tomcat Version</title>
</head>
<body>
<h2>Tomcat Version</h2>
<pre>${pageContext.servletContext.serverInfo}</pre>
<h2>Servlet Version</h2>
<pre>${pageContext.servletContext.majorVersion}.${pageContext.servletContext.minorVersion}</pre>
</body>
</html>