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:
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 :)