zoukankan      html  css  js  c++  java
  • jodd-servlet工具集锦

    Jodd提供了许多servlet和jsp相关的工具。

    Utils

      ServletUtils类集成了不同的servlet工具,你可以检测multipart请求,读取授权头,下载预备,cookie操作,读取请求报文,从不同scope中读取值,检测绝对Url,检测servlet 2.5的版本,保护缓存等等。

      DispatcherUtil提供了一个方法,如including,forwarding和redirecting。它也返回很多不同的路径相关信息,例如Context路径,查询字符串等等。

    Map wrappers

    Jodd为请求,响应,session提供了Map的包装类。这些包装类就是各种servlet的Map 适配器,外部用户不直接使用它们。它们适用于分离Servlet的实现代码。

    File upload

    jodd为multipart请求和文件上传提供了一整套类。

    上传的文件可以下载到内存,文件系统或者根据大小进行适配。

    Listeners and broadcasters

      HttpSessionListenerBroadcaster仅仅在session创建或者销毁时发送事件到注册的session监听器上。

      RequestContextListener保存当前线程的请求。

    JSP Tag library

      jodd提供了一套微型但非常高效的标签库。它提供了一个通用功能:不同的遍历标签、条件和分钟标签,设置和读取变量标签等等,想了解更多,请查看Jodd JSP tag library. 文件名称为Jodd-taglib.tld。

    CSRF shield

      jodd提供了简单有效的csrf(cross-sit request forgery)保护。

        <tag>
            <name>csrfToken</name>
            <tag-class>jodd.servlet.tag.CsrfTokenTag</tag-class>
            <body-content>empty</body-content>
            <attribute>
                <name>name</name>
                <required>false</required>
                <rtexprvalue>true</rtexprvalue>
            </attribute>
        </tag>

    实现:

        @Override
        public void doTag() throws IOException {
            JspContext jspContext = this.getJspContext();
    
            // generate token
            HttpServletRequest request = (HttpServletRequest) ((PageContext) jspContext).getRequest();
            HttpSession session = request.getSession();
            String value = CsrfShield.prepareCsrfToken(session);
            if (name == null) {
                name = CsrfShield.CSRF_TOKEN_NAME;
            }
            jspContext.getOut().write("<input type="hidden" name="" + name + "" value="" + value + ""/>");
        }

    Filters

    Jodd只提供了很少一些servlet过滤器:GZipFilter,

    CharacterEncodingFilter,RemoveSessionFromUrlFilter。

    然而,jodd还有许多过滤器相关的类,如快速字节数组和字符数组包装,包括更高级的BufferResponseWrapper。

    参考文献:

    http://jodd.org/doc/servlets.html

  • 相关阅读:
    codec功能简介
    dtmf原理说明
    linux的vm.overcommit_memory的内存分配参数详解
    Hibernate与Sleep的区别
    简单的读写-simple_read_from_buffer
    linux delay sleep
    Linux系统上的popen()库函数
    Linux中popen函数的作用小结
    ulimit 命令详解
    LTE Cat1有什么用?基于4G LTE打造cat1,弥补NB-IoT和5G的空缺
  • 原文地址:https://www.cnblogs.com/davidwang456/p/4647487.html
Copyright © 2011-2022 走看看