JSTL Function Tags

JSTL Function Tags
2011年09月01日
  Now, let’s have a look at the JSTL Function tag. Create a new JSP. Let’s name it Jstl_Functions_Tags.jsp. Then create a new link to direct to this new JSP. JSTL Functions Tags String Manipulations Do not forget to include JSTL taglib directive for prefix fn in our JSP. Here is how to import the fn JSTL taglib directive. The JSTL functions tag will mainly deal with string manipulation. Let’s try some of them. Above codes are used to set a fixed string to variable “sentence” and print it out for display. Next, please pay attention on how we are going to combine JSTL core tag with JSTL function tag. Above codes will print out the length of variable “sentence”. It will produce 35 since all characters are counted. Above codes are used to convert our “sentence” to UPPER or LOWER case. Above codes are used to trim the “sentence” and count the length of trimmed “sentence”. Trimming the sentence means that we are removing the extra spaces (if any) in the string either in front or in back. You need to know that the spaces within the string will NOT be trimmed. It should produce 33 since the spaces at the beginning and at the end will be discarded. While the sample above of fn:replace will replace all occurrences of spaces with underscores.
  
  
  
  
  The fn:substring will take 3 parameters. 1stparameter is our “sentence” variable itself. 2ndparameter is for the starting point and 3rdparameter is where it must stop to return result of substring. More advanced substring functions are fn:substringAfter and fn:substringBefore. See at the screenshot to see how they work.
  And the fn:indexOf will return the position of defined character in our “sentence”.
  
  
  
  
  fn:contains will return boolean value true if correct and false otherwise. However, it is case sensitive and will sensitively check for the lower case and upper case of the string. fn:containsIgnoreCase work in the same way as fn:contains but it is not case sensitive which means that it will not care whether it is in lower case or in upper case. fn:startsWith and fn:endsWith will also return boolean to check whether the “sentence” starts or ends with corresponding given value. Again, clean build the project and run the project. The index.jsp will appear as usual and click the “Jstl_Functions_Tags” to see the result.
  
  
  6. Conclusion Now we have known what JSTL is and how to use it. Use JSTL anytime when possible. JSTL could empower our web app. From what we learnt, we could think of when or in what conditions JSTL could be used for. Some examples of use of JSTL are display format and internationalization
  print out values from servlets response-request or even database values as in work with POJO orjava bean
  validating users’ input on UI
  parsing users’ input value
  URL handling
  You could think of other several examples andextendyour knowledge on JSTL. And apply it on your project.
  
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值