zoukankan      html  css  js  c++  java
  • JavaWeb发送状态码

    一.发送状态码

      1.状态码的发送可由httpServletResponse对象的方法来实现

      2.有三种发送状态码的方法:

        >SendError(int sc):发送错误状态码,如404,500

        >SendError(int sc,String msg):发送错误状态码,顺带一条错误提示信息

        >SendStatus(int sc):发送成功状态码,如:200,302

    二.代码实例:

    package cn.xxx.Servlet;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class AServlet extends HttpServlet {
    
    
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            response.sendError(404,"你要的资源就不给你!");
        }
    
    
    
    }

      

    1.当我们访问AServlet时,出现如下界面:

    >

  • 相关阅读:
    mysql中文乱码的一点理解
    Linux 运行进程实时监控pidstat命令
    深入理解“系统平均负载”
    进程和线程的区别
    vmstat命令
    grep命令
    top命令
    Shell脚本获取本机ip
    CentOS7防火墙(firewall)配置
    大数据测试
  • 原文地址:https://www.cnblogs.com/ibcdwx/p/12291180.html
Copyright © 2011-2022 走看看