What do the Spring Framework JSP Tags do?

I am currently mapping some HTML tags over to Spring tags in my JSP files. Spring MVC has two tag libraries: spring.tld and spring-form.tld

I understand the descriptions for the tags defined in the Form Tag Library, so I know which HTML tags to map to Spring Form tags. However, I don't know how to use the Spring Tag Library at all. The defined tags and the given descriptions are as follows:

  • htmlEscape : Sets default HTML escaping value for the current page. Overrides a "defaultHtmlEscape" context-param in web.xml, if any.
  • escapeBody : Escapes it's enclosed body content, applying HTML escaping and/or JavaScript escaping. The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • message : Retrieves the message with the given code, or text if code isn't resolvable. The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • theme : Retrieves the theme message with the given code, or text if code isn't resolvable. The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • argument : Argument tag based on the JSTL fmt:param tag. The purpose is to support arguments inside the spring:message and spring:theme tags.
  • hasBindErrors : Provides Errors instance in case of bind errors. The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • nestedPath : Sets a nested path to be used by the bind tags path.
  • bind : Provides BindStatus object for the given bind path. The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • transform : Provides transformation of a variables to Strings, using an appropriate custom PropertyEditor from BindTag (can only be used inside BindTag). The HTML escaping flag participates in a page-wide or application-wide setting (ie by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
  • url : URL tag based on the JSTL c:url tag. This variant is fully backwards compatible with the standard tag. Enhancements include support for URL template parameters.
  • param : Parameter tag based on the JSTL c:param tag. The sole purpose is to support params inside the spring:url tag.
  • eval : Evaluates a Spring expression (SpEL) and either prints the result or assigns it to a variable.
  • I don't understand the descriptions in the slightest. Escaping, theme, JSTL, binding, nested path, Spring expressions etc. - what are they talking about?

    What do these tags do? Which tags do they substitute in my JSP files? I tried searching online but all the search results are about the Form Tag Library (spring-form.tld) not the Tag Library (spring.tld) which is the one I'm having trouble with.

    Edit : I'm migrating from Struts 1.1 to Spring 4.1.6. Part of the steps involve converting to Spring-compatible tags in the JSP files. The original JSP files do not contain any taglib directives, so I am guessing only HTML tags are used in the original code.


    Then the form taglib is used to bind easily your backend(s) object(s) with your form's fields. Declare these spring taglib with

    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    

    And use it inside your form with tags as:

     <form:form>
        <table>
           <tr>
              <td>First Name:</td>
              <td><form:input path="user.firstName"/></td>
           </tr>
           <tr>
              <td>Last Name:</td>
              <td><form:input path="user.lastName"/></td>
           </tr>
           <tr>
              <td colspan="2">
                 <input type="submit" value="Save!"/>
              </td>
           </tr>
        </table>
    </form:form>
    

    Escaping is relative to HTML encoding for special chars. It could raise some security problems if you do not use it accordingly within your application.

    Message is relative to i18n : you can build easily a locale switcher between some countries. The way to retrieve all the translations is by using that taglib.

    Theme is relative to the Look and Feel of your webapplication. You can build an easily theme switcher for your endusers with the use of these taglib.

    Binding is relative to handle many fields from your DTO inside your views, particularly when you have submitted a form.

    JSTL is a way to handle many things in your JSPs, developed many years before the spring-taglibs. JSTL stays a valid choice, but in a lower level of your view layer development. It will be longer, and maybe harder, to do the same the job.

    For your JSPs headers in order to declare your taglib's imports:

    <%@ page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
    <%@taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    <%@page session="true"%>
    

    Of course it is only an example, with a bonus: the spring-security taglib import for handle authentication stuff inside an admin's area JSP :)

    Discover these world with the current official documentation. Looking inside the "22.5 JSP & JSTL" section page 555, and looking forward in the docs spring:bind or spring:message , etc. You find find that you will need to understand everything :)

    链接地址: http://www.djcxy.com/p/76590.html

    上一篇: scriptlet有什么问题,以及使用什么

    下一篇: Spring Framework JSP标记有什么作用?