使用jsp,tag提取字符串中的单词
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提取字符串中的单词的更多相关文章
- [LeetCode] Reverse Words in a String 翻转字符串中的单词
Given an input string, reverse the string word by word. For example, Given s = "the sky is blue ...
- [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 ...
- C++ 提取字符串中的数字
C++ 提取字符串中的数字 #include <iostream> using namespace std; int main() { ] = "1ab2cd3ef45g&quo ...
- [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 ...
- [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 ...
- C#版(击败97.76%的提交) - Leetcode 557. 反转字符串中的单词 III - 题解
版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. Leetcod ...
- Leetcode#557. Reverse Words in a String III(反转字符串中的单词 III)
题目描述 给定一个字符串,你需要反转字符串中每个单词的字符顺序,同时仍保留空格和单词的初始顺序. 示例 1: 输入: "Let's take LeetCode contest" 输 ...
- java通过StringToKenizer获取字符串中的单词根据空格分离-简写版
public class StringToKenizer { public static void main(String[] args) { String strin = "Hello J ...
- java通过StringToKenizer获取字符串中的单词根据空格分离-详情版
public class DaXie { public static void main(String[] args) { String strin = "Hello Java World! ...
随机推荐
- Visual Studio高效实用的扩展工具、插件
说明: 对一个有想法的程序员来说,善于使用一款高效的开发工具是很重要的,今天给大家介绍的是宇宙第一IDE vs用起来很不错的开发工具,假如大家觉得不错也可以尝试的用用,毕竟对于我们这些一天一大半的时间 ...
- 模式识别笔记3-支持向量机SVM
1. 线性SVM 对两类点的划分问题,这里对比下逻辑回归和SVM的区别: 逻辑回归的思想是,将所有点到决策平面的距离作为损失来进行训练,目标是到决策平面的距离和最小 SVM的思想是,只关注支持向量(图 ...
- 从fastjson多层泛型嵌套解析,看jdk泛型推断
给你一组json数据结构,你把它解析出来到项目中,你会怎么做? // data1 sample { "code" : "1", "msg" ...
- java集合常见面试题
1. Array和ArrayList的区别,什么时候更合适用Array a) Array是数组,可以容纳基本类型和对象,而ArrayList是集合,只能容纳对象 b) Array是 ...
- 一些关于IO流的问题
一:知识点 二:代码 1.阅读下面程序段: BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(&quo ...
- mac-os安装autojump
一 概念 autojump是一个命令行工具,它可以使用快捷命令,直接跳转到配置好的目录,而不用管现在身在何处,依赖zsh. 一 安装 安装zsh:sh -c "$(curl -fsSL ht ...
- Python就业指导
一年一度的金三银四招聘旺季又要到了,最近有很多同学希望我能给他们一些关于python的就业指导:之前出过一期关于java的就业指导,但是并不是很完善,所以希望这期关于python的就业指导能够很全面很 ...
- Java枚举:小小enum,优雅而干净
<Java编程思想>中有这么一句话:“有时恰恰因为它,你才能够‘优雅而干净’地解决问题”——这句话说的是谁呢?就是本篇的主角——枚举(Enum)——大家鼓掌了. 在之前很长时间一段时间里, ...
- 1.6W star 的 JCSprout 阅读体验大提升
万万没想到 JCSprout 截止目前居然有将近1.6W star.真的非常感谢各位大佬的支持. 年初时创建这个 repo 原本只是想根据自己面试与被面试的经历记录一些核心知识点,结果却是越写越多. ...
- java游戏开发杂谈 - java是什么
java是一门编程语言, 它有三个开发平台:j2ee.j2se. j2me.(其实android也算一个了) j2ee, 也就是web开发,比如网站.各类管理系统,主要是围绕数据库.网页等进 ...