zoukankan      html  css  js  c++  java
  • get和post的区别与乱码问题解决

    ★ get和post的区别:
        1.get请求通过url地址发送请求参数,可以在地址栏上直接显示
        2.post请求通过请求体发送请求参数,不会再地址栏上显示
        3.get在地址栏显示请求参数安全性低,而post请求要好一些
        4.get请求通过地址栏发送请求参数,长度有限制,最大发送255个字符。
            post请求通过请求体发送请求参数,大小没有限制。
        5.一般开发中提交表单时均使用post请求,get请求一般不用
     
    ********************************* **************************解决请求时乱码,将字符集统一,推荐utf-8******************************************************************
    ★ 在Tomcat服务器中server.xml 添加()
            <Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
     
     
     ★  编码:
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
     
            response.setContentType("text/html;charset=utf-8");
            process(request,response);
     
        }
     
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
     
            request.setCharacterEncoding("utf-8");
            process(request,response);
     
        }
     
        public void process(HttpServletRequest request, HttpServletResponse response)
                          throws ServletException, IOException {
     
        }
     
     
     
    - 转发的路径由服务器解析,设置绝对路径时不需要加项目名
     - 重定向的路径由浏览器解析,设置绝对路径时需要加上项目名
    请求的转发:
        request.getRequestDispatcher("/pages/manager/**.jsp").forward(request, response);
    请求的重定向:
        response.sendRedirect(request.getContextPath()+"/manager/***?method=find");
  • 相关阅读:
    obj文件可视化
    TypeError: unsupported operand type(s) for +: 'range' and 'range'
    ubuntu截屏软件shutter
    什么是Redis缓存穿透、缓存雪崩和缓存击穿
    在 ASP.NET Core 5.0 中访问 HttpContext
    如何使用带有BOM的UTF8编码的C#中的GetBytes()?
    ASP.NET Core 5.0 Web API 自动集成Swashbuckle
    ASP.NET Core 5.0 的新增功能
    面试被问到SQL | delete、truncate、drop 有什么区别?
    3个值得学习和练手的.net企业级开源项目,强烈推荐
  • 原文地址:https://www.cnblogs.com/libingbin/p/5955203.html
Copyright © 2011-2022 走看看