zoukankan      html  css  js  c++  java
  • 显示Servlet API主要版本,次要版本以及服务器系统信息

     1 package com.mhb;
     2 
     3 import java.io.IOException;
     4 import java.io.PrintWriter;
     5 
     6 import javax.servlet.ServletContext;
     7 import javax.servlet.ServletException;
     8 import javax.servlet.http.HttpServlet;
     9 import javax.servlet.http.HttpServletRequest;
    10 import javax.servlet.http.HttpServletResponse;
    11 
    12 public class ServletContextDemo extends HttpServlet {
    13 
    14 public void init() throws ServletException {
    15 }
    16 
    17 public void doGet(HttpServletRequest request, HttpServletResponse response)
    18 throws ServletException, IOException {
    19 //设置输出内容格式和编码
    20 response.setContentType("text/html;charset=gb2312");
    21 PrintWriter out = response.getWriter();
    22 //获得ServletContext实例
    23 ServletContext application = getServletContext();
    24 //主要的Servlet API版本
    25 int magorVersion = application.getMajorVersion();
    26 //次要的Servlet api版本
    27 int minorVersion = application.getMinorVersion();
    28 //服务器版本
    29 String info = application.getServerInfo();
    30 
    31 out.println("<html>");
    32 out.println("<body>");
    33 out.println("主要Servlet API版本:"+magorVersion+"<br />");
    34 out.println("次要Servlet API版本:"+minorVersion+"<br />");
    35 out.println("服务器版本:"+info+"<br />");
    36 out.println("</body>");
    37 out.println("</html>");
    38 
    39 }
    40 
    41 public void doPost(HttpServletRequest request, HttpServletResponse response)
    42 throws ServletException, IOException {
    43 }
    44 
    45 public void destroy() {
    46 super.destroy(); 
    47 }
    48 }

    浏览器显示:

  • 相关阅读:
    ubuntu查看系统负载和程序运行状况
    ubuntu 离线装包
    python如何离线装包 离线如何部署python环境
    开发板上如何配置apahe2+mysql+php7
    c++指针实例
    nginx反向代理nginx,RealServer日志打印真实ip
    lvs+keep搭建高可用web服务
    linux一键安装vncserver脚本
    ansible 学习与实践
    centos7编译安装MySQL5.7.9
  • 原文地址:https://www.cnblogs.com/tdcqma/p/4757871.html
Copyright © 2011-2022 走看看