• java_day23_表单,乱码问题


    表单

    一.get请求网站的过程

     

    二.乱码问题

      1.request发生的乱码

        解决乱码方式一:

         String keyword = req.getParameter("keyword");

         byte[] bytes = keyword.getBytes("iso-8859-1");//tamcat默认解码8859-1

         keyword = new String(byets,"utf-8");//编码(8859)-解码-编码(utf8)

        解决乱码方式二:

          修改tomcat默认配置:tomcat-conf-server.xml

      

      2.response发生的乱码

      

    三.获取表单参数

      1.html页面:

        <form action="/browser" method = "get">  //action指向跳转的页面,method指方式

          <input type="text" name="keyword">  //输入文本框需要设置名字

          <input type="submit" value="百度一下">

        </form>

      2.servlet获取表单参数

        resp.setContentType("text/html;charset=utf-8");//响应头的编码信息

        String keyWord = req.getParameter("keyword"); //获取input的name为keyword的输入信息

      3.request封装了http请求的所有数据,请求行,请求头,请求体.

        1).获取客户端ip

          String remoteAddr = request.getRemoteAddr();

        2).获取请求方式

          String method  = request.getMethod();

        3).判断用户浏览器/操作系统

          String userAgent = request.getHeader("user-agent")

       

        

        

      

     

     

      

      

  • 相关阅读:
    sql 内链接
    使用python 写一个自动windows桌面壁纸的程序
    在windows使用pyinstall 打包 flask 再使用nsis软件打包成安装包
    超微主板ibm密码
    jenkins邮件模板
    gp集群常用命令
    shell小知识
    Linux配置免密
    文件基础命令
    华为初识命令
  • 原文地址:https://www.cnblogs.com/memo-song/p/9032974.html
Copyright © 2020-2023  润新知