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. 【Caffe篇】--Caffe从入门到初始及各层介绍

    一.前述 Caffe,全称Convolutional Architecture for Fast Feature Embedding.是一种常用的深度学习框架,主要应用在视频.图像处理方面的应用上.c ...

  2. colly源码学习

    colly源码学习 colly是一个golang写的网络爬虫.它使用起来非常顺手.看了一下它的源码,质量也是非常好的.本文就阅读一下它的源码. 使用示例 func main() { c := coll ...

  3. ASP.NET Core MVC应用程序中的后台工作任务

    在应用程序的内存中缓存常见数据(如查找)可以显着提高您的MVC Web应用程序性能和响应时间.当然,这些数据必须定期刷新. 当然你可以使用任何方法来更新数据,例如Redis中就提供了设定缓存对象的生命 ...

  4. ES 06 - 通过Kibana插件增删改查ES中的索引文档

    目录 1 document的结构 2 document的常见CRUD操作 2.1 添加商品: 添加文档并建立索引 2.2 查询商品: 检索文档 2.3 修改商品: 替换文档 2.4 修改商品: 更新文 ...

  5. Tomcat NIO 模型的实现

    Tomcat 对 BIO 和 NIO 两种模型都进行了实现,其中 BIO 的实现理解起来比较简单,而 NIO 的实现就比较复杂了,并且它跟常用的 Reactor 模型也略有不同,具体设计如下: 可以看 ...

  6. RDIFramework.NET ━ .NET快速信息化系统开发框架 V3.2版本正式发布

     RDIFramework.NET .NET快速信息化系统开发框架 V3.2版本 正式发布 精益求精求完美! 1.RDIFramework.NET框架介绍 RDIFramework.NET,基于.NE ...

  7. java爬虫系列第五讲-如何使用代理防止爬虫被屏蔽?

    本文内容 1.分析一下爬虫存在的问题及解决方案 2.webmagic中代理的使用 3.目前市面上一些比较好用的代理服务器 存在的问题 我们在使用爬虫过程中,大多都会遇到这样的问题:突然某一天爬虫爬不到 ...

  8. 26 , CSS 构造表单

    1. 表单标签使用 2. 下拉菜单背景 3. 滚动条的使用 4. 结构化表单布局 1 1 1 1. . . . 表单标签的使用 <label for=”name”>姓名: <inpu ...

  9. setTimeout传参 和 运行机制

    1.setTimeout 传参数 setTimeout还允许添加更多的参数.它们将被传入推迟执行的函数(回调函数) 上面代码中,setTimeout共有4个参数.最后那两个参数,将在1000毫秒之后回 ...

  10. 关于computed使用时报no-side-effects-in-computed-properties错误

    不要在计算属性内直接修改data里面的数据,eslint会报 no-side-effects-in-computed-properties 错误,如果非要改可以写在一个函数里,然后在计算属性里调用该函 ...