Let’s see how it works. Create 2 new JSP called JstL_Core_Tags_Redirect.jsp and Jstl_Core_Tags_Import.jsp.
Add this to Jstl_Core_Tags_Redirect.jsp
It is going to redirect the page back to index.jsp
Add this to Jstl_Core_Tags_Import.jsp
It will import or include index.jsp after Jstl_Core_Tags_Import.jsp loads.
This is what we get when we run Jstl_Core_Tags_Redirect.jsp. Just type the address as shown in circled area and the page will redirect us back to index.jsp.
Interesting right? Well, do same thing for Jstl_Core_Tags_Import.jsp. Open browser then type the full address manually and we will get index.jsp is loaded after Jstl_Core_Tags_Import.jsp loads.
4. Implementation of JSTL Formatting Tags
Now, you should have understood the JSTL core tags very well. As you can see, the JSP is more readable and more maintainable. If you try to achieve all the previous examples using scriptlets, your JSP may be larger in size and much more complex. Well, it is time to move on to the second JSTL tags which is JSTL Formatting tags. Similarly, create a new JSP and name it Jstl_Fmt_Tags.jsp. Add one more link in our existing index.jsp but this time let’s make it in another table to ensure the simplicity of the example.
| Internationalizing and Formatting |
Now, we need to include another JSTL tag. Here is how to import the fmt JSTL taglib directive.
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
Let’s try something interesting on the JSTL internationalization support.
Above codes will simply print out our default locale. The value will be retrieved from each client’s specific browser. In IE browser, you can find your Locale on Tools-Internet Options… and then Languages…
Ok now we need to create properties files under WEB-INF/classes/ directory. These files often called as resource bundle files and should be located under this directory as it will be included in the classpath. If the file is not within the classpath, you will not be able to access it from your application. Normally, resource bundle properties files will be the place to store the language translations.
Comments
Post a Comment