检查字符串是否包含数字
生活随笔
收集整理的這篇文章主要介紹了
检查字符串是否包含数字
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
創建JavaBean類
創建index.jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>判斷字符串是否包含數字</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">table{border: 1px solid;border-color: green;font-family:華文細黑;font-size: 13px;color:gray;}input{font-family:華文細黑;font-size: 13px;color:gray;}</style></head><body><form action="check3.jsp" method="post"><table><tr><td align="right">請輸入字符串:</td><td><input type="text" name="str" size="30"/></td></tr> <tr><td colspan="2" align="center"><input type="submit" value="檢 查" /></td></tr></table> </form></body> </html>創建check.jsp頁面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <%request.setCharacterEncoding("UTF-8");%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head> <title>檢查</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><style type="text/css">table{border: 1px solid;border-color: green;color: green;font-size: 13px;font-family: 華文細黑;}</style></head><body><%String str = request.getParameter("str");%><!-- 使用useBean動作標簽導入JavaBean對象 --><jsp:useBean id="strBean" class="com.cn.zj.bean.StringUtil3"></jsp:useBean><!-- 對StringUtil類的str屬性賦值 --><jsp:setProperty property="str" name="strBean" value="<%=str %>"/><table><tr><td align="right">輸入的字符串:</td><td><!-- 從StringUtil對象中獲得str的屬性值 --> <jsp:getProperty property="str" name="strBean"/></td></tr><tr><td align="right">是否包含數字:</td><td> <!-- 從StringUtil對象中獲得hasNum的屬性值 --> <jsp:getProperty property="hasNum" name="strBean"/></td> </tr><tr><td align="right">去掉數字后的字符串:</td><td> <!-- 從StringUtil對象中獲得othersStr的屬性值 --> <jsp:getProperty property="othersStr" name="strBean"/></td></tr></table> </body> </html>總結
以上是生活随笔為你收集整理的检查字符串是否包含数字的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 判断字符串是否以指定字符开头
- 下一篇: 判断用户输入的日期是否为当前日期