JSP to determine whether the list contains string implementation method _jsp programming

Source: Internet
Author: User
Tags arrays

There are Fn:contains (STR,STR) methods in Jstl to determine whether a string contains another string, but there is no way to tell if the list contains string, so you write a method yourself

Contains.tag:

<%@ tag import= "java.util.List"%>
<%@ tag import= "Org.apache.commons.lang3.StringUtils"%>
< %@ tag import= "java.util.Arrays"%>
<% @tag pageencoding= "UTF-8"%> <%@
attribute name= "Srcstr" Type= "Java.lang.String" required= "true"%>
<%@ attribute name= "Separatorchars" type= "java.lang.String" Required= "false"%>
<%@ attribute name= "str" type= "java.lang.String" required= "true"%>
  String sepchars=separatorchars==null? " -": Separatorchars;
  string[] Splitchars = Stringutils.split (Srcstr, sepchars);
  list<string> list = Arrays.aslist (splitchars);
  if (List.contains (str))
  {%>
    <jsp:doBody/>
<%}
%>

Then add a sentence to the page of the method you want to use:

<%@ taglib prefix= "gms" tagdir= "/web-inf/tags"%>

So you can use it directly

<gms:contains srcstr= "${srcstr}" str= "${str}" > str </gms:contains>

That's the way to judge.

The above is small series for everyone to bring the JSP to determine whether the list contains a string of the implementation of all the content, I hope that we support cloud-Habitat Community ~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.