• Servlet总结


    一,servlet
    运行在服务器端,用来处理请求和响应的Java程序(组件)

    二,使用servlet
    1,继承HttpServlet
    2,重写方法(service[doGet doPost])
    3,request[请求] response[响应]

    4,配置web.xml[servlet servlet-mapping] [url-pattern: /....]

    5,请求方式: form表单请求[get post] a标签方式 <a href="zhuce?name=值1&pwd=值2">提交</a>

    三,servlet的生命周期
    1,实例化[tomcat启动时]
    2,初始化[init 第一次访问时]
    3,事物处理[service 多次执行(多线程)]
    4,销毁[destory tomcat停止时]

    四,中文乱码的处理方式
    1,get提交
    原因:编码[UTF-8]和解码[ISO8859-1]的方式不同 (name)
    1) 解决方案: 逆向返回 byte b[]=name.getBytes("ISO8859-1"); name=new String(b,"UTF-8");

    2)解决方案: 在tomcat中的conf中的server.xml中加 URIEncoding="utf-8";


    2,post提交
    原因: 编码[utf-8]和解码[根据系统不同而不同]方式不同
    解决方案: 自定义解码集[utf-8]
    request.setCharacterEncoding("utf-8");
    3,响应处理
    自定义编码和解码的字符集
    response.setCharacterEncoding("utf-8"); 设置编码方式
    response.setContentType("text/html;charset=utf-8"); 设置解码方式


    五,页面跳转的方式
    1,请求转发 reques.getRequestDispatcher("路径").forWord(request,response);
    1)一个请求 2)url不改变 3)最好是servlet 4)request设置的属性不变

    2,响应重定向 response.sendRedirect("路径");
    1)两个请求 2)url改变 3)最好是相对路径 4)request设置的属性改变

    六,ServletContext(上下文对象)(一个servelet对象只有一个上下文对象)
    getAttribute() setAttribute()

    七,Session (会话跟踪技术)
    getAttribute() setAttribute() removeAttribute()

  • 相关阅读:
    校验规则,纯数字。几位有效数字,保留几位小数
    银行卡校验规则(Luhn算法)
    forEach兼容ie8
    node.js
    gulp
    observer
    webpack.config.js 配置
    内存泄漏(Memory Leak)
    cdn
    前端 各种插件的官网
  • 原文地址:https://www.cnblogs.com/afengboke/p/4610852.html
Copyright © 2020-2023  润新知