JSP中调用Tag
在表单中输入字符串,提取其中的单词

参考代码:
giveString.jsp

<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="words" %> <!-- 引入标记库 -->
<body bgcolor=pink>
<form action="" method=get name=form>
请输入字符串:<input type="text" name="a">
<input type="submit" name=submit value="提取"></form>
<% String s=request.getParameter("a"); <!-- 取表单中输入的值 -->
%>
字符串<words:WordList0545 str="<%=s %>"></words:WordList0545>
<br><h3><%=s%><br></h3>中的全部单词解析为:
<%
for(int i=0;i<wordList.size();i++){
out.print("<br>"+wordList.get(i));
}
%>
</body>
</html>

 WordList.tag

<%@ tag  pageEncoding="gb2312" %>
<%@ tag import="java.util.*" %>
<%@ attribute name="str" required="true" %>
<%@ variable name-given="wordList"
variable-class="java.util.ArrayList" scope="AT_END" %>
<%
ArrayList<String> list=new ArrayList<String>(); //返回给JSP页面的list对象
String regex="[\\s\\d\\p{Punct}]+"; //空格、数字和符号(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)组成的正则表达式
String words[]=str.split(regex);
for(int i=0;i<words.length;i++){
list.add(words[i]);
}
jspContext.setAttribute("wordList",list); ////将list对象返回给JSP页面
%>

  运行界面

 

使用jsp,tag提取字符串中的单词的更多相关文章

  1. [LeetCode] Reverse Words in a String 翻转字符串中的单词

    Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...

  2. [LeetCode] Reverse Words in a String II 翻转字符串中的单词之二

    Given an input string, reverse the string word by word. A word is defined as a sequence of non-space ...

  3. C++ 提取字符串中的数字

    C++ 提取字符串中的数字 #include <iostream> using namespace std; int main() { ] = "1ab2cd3ef45g&quo ...

  4. [Swift]LeetCode434. 字符串中的单词数 | Number of Segments in a String

    Count the number of segments in a string, where a segment is defined to be a contiguous sequence of ...

  5. [Swift]LeetCode557. 反转字符串中的单词 III | Reverse Words in a String III

    Given a string, you need to reverse the order of characters in each word within a sentence while sti ...

  6. C#版(击败97.76%的提交) - Leetcode 557. 反转字符串中的单词 III - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...

  7. Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)

    题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...

  8. java通过StringToKenizer获取字符串中的单词根据空格分离-简写版

    public class StringToKenizer { public static void main(String[] args) { String strin = "Hello J ...

  9. java通过StringToKenizer获取字符串中的单词根据空格分离-详情版

    public class DaXie { public static void main(String[] args) { String strin = "Hello Java World! ...

随机推荐

  1. Linux命令大全汇总,让你工作更有效率!

    基础命令 useradd:用户名 -m:创建新用户 passwd 用户名:为用户设置密码(当创建新用户后,就需要设置密码) whoami:查看当前用户名 exit :退出当前用户,返回之前切换过来的用 ...

  2. django框架使用mysql步骤

    在创建好django项目的基础上来讲解使用orm框架 注意:首先在mysql中手动或者通过命令创建一个数据库,我先创建一个名为orm的数据库. 1:在项目文件夹中的settings.py文件中配置my ...

  3. Struts第一个案例搭建

    1.引入依赖 <dependency> <groupId>javaee</groupId> <artifactId>javaee-api</art ...

  4. Python基础(os模块)

    os模块用于操作系统级别的操作: os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当 ...

  5. 由ODI初始化资料档案库(RUC)引起修改ORACLE字符集(ZHS16GBK-AL32UTF8)

    如果要部署代理,需要在RUC中进行资料档案库的初始化,这样可以免去配置代理的繁琐.在RUC连接数据库时会有先决条件检查,如果出现下图的警告,就需要在ORACLE中修改字符集. 具体操作如下: 登录SQ ...

  6. Asp.Net Core中服务的生命周期选项区别和用法

    在做一个小的Demo中,在一个界面上两次调用视图组件,并且在视图组件中都调用了数据库查询,结果发现,一直报错,将两个视图组件的调用分离,单独进行,却又是正常的,寻找一番,发现是配置依赖注入服务时,对于 ...

  7. Redis~Linux环境下的部署

    回到目录 Redis的生产环境建议部署到linux上,而在开发时可以连接windows版本,下面介绍如何在linux上部署redis. $ wget http://download.redis.io/ ...

  8. 【大数据安全】Apache Kylin 安全配置(Kerberos)

    1. 概述 本文首先会简单介绍Kylin的安装配置,然后介绍启用Kerberos的CDH集群中如何部署及使用Kylin. Apache Kylin™是一个开源的分布式分析引擎,提供Hadoop/Spa ...

  9. Python 里的「单分派泛函数」到底是什么?

    泛型,如果你学过Java ,应该对它不陌生吧.但你可能不知道在 Python 中(3.4+ ),也可以实现简单的泛型函数. 在Python中只能实现基于单个(第一个)参数的数据类型来选择具体的实现方式 ...

  10. 通过 JSONP 实现跨域请求

    优质参考资料:https://www.cnblogs.com/chiangchou/p/jsonp.html https://blog.csdn.net/hansexploration/article ...