使用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! ...
随机推荐
- 简单读!zookeeper单机模式的启动逻辑
zk用处如此之多,以至于每个地方都要你理解zk原理! 请按如下操作姿势打开: 1. 打开zk的git仓库地址:https://github.com/apache/zookeeper , 确认过眼神,它 ...
- 面向对象(__str__和__repr__方法)
#Author : Kelvin #Date : 2019/1/21 16:19 class App: def __init__(self,name): self.name=name # def __ ...
- Notepad++ 安装连接服务器的NppFTP插件
用Notepad++连接服务器,可以随时编辑一些文件不用特意下载.有时重做系统经常忘记一些插件备份到了哪.再此做个记录,方便重新安装. 下载完NppFTP插件,解压后将bin文件夹下的NppFTP.d ...
- 286万QPS!腾讯云TDSQL打造数据库领域的“超音速战机”
Bloodhound SSC超音速汽车将陆地极限速度提升到1678公里/小时,号称陆地“超音速战斗机”.无独有偶,同样也在2017年,在英特尔®.腾讯金融云团队的共同见证下,腾讯云数据库TDSQL采用 ...
- 服务器linux centos 7.4 搭建ftp服务器
此操作是在腾讯云服务器linux centos 7.4 完成搭建ftp服务器 vsftpd 的: 安装 vsftpd $ yum install vsftpd -y 启动 $ service vsft ...
- 用.net写Textbox控件关于数字的判断的二则方法
方法一.使用textboxSelected事件进行判断首界面源码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- [TCP/IP] 计算机网络性能指标
速率:连接在计算机网络上的主机在数字信道上传输数据位数的速率单位是 b/s kb/s mb/s gb/s带宽:数字信道所能传输的最高数据率 查看我的网卡是144Mbps吞吐量:单位时间内通过某个网络的 ...
- python3 爬取boss直聘职业分类数据(未完成)
import reimport urllib.request # 爬取boss直聘职业分类数据def subRule(fileName): result = re.findall(r'<p cl ...
- MySQL优化面试
原则:尽量使用整型表示字符串 存储IP INET_ATON(str),address to number INET_NTOA(number),number to address MySQL内部的枚举类 ...
- vue-router 通过路由来实现切换头部标题
在做单页面应用程序时,一般页面布局头尾两块都是固定在布局页面,中间为是路由入口.这时访问页面时头部标题不会变,该问题的解决方案如下: 通过采用组件内路由卫士(beforeRouterEnter.bef ...