检查字符串是否以指定字符串开头
2018-08-18 本文已影响0人
神坛下的我
StringUtil7.java
public class StringUtil7 {
private String startStr;//指定开头的字符串
private String str;//被判断的字符串
private boolean check;
public String getStartStr() {
return startStr;
}
public void setStartStr(String startStr) {
this.startStr = startStr;
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public boolean isCheck() {
/*该方法判断字符串是否以指定字符开头*/
return str.startsWith(startStr);
}
}
index.jsp
<body>
<form action="result.jsp" method="post">
<table>
<tr>
<td align="right">请输入字符串:</td>
<td><input type="text" name="str" size="40"/></td>
</tr>
<tr>
<td align="right">请输入开头的字符串:</td>
<td><input type="text" name="startStr"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="验证"/></td>
</tr>
</table>
</form>
</body>
result.jsp
<body>
<%
request.setCharacterEncoding("utf-8");
String str= request.getParameter("str");
String startStr= request.getParameter("startStr");
%>
<jsp:useBean id="strBean" class="com.count.StringUtil7"></jsp:useBean>
<jsp:setProperty property="str" name="strBean" value="<%=str %>"/>
<jsp:setProperty property="startStr" name="strBean" value="<%=startStr %>"/>
<table>
<tr>
<td>过滤之前的字符串:</td>
<td align="left">
<jsp:getProperty property="str" name="strBean"/>
</td>
</tr>
<tr>
<td>开头的字符串:</td>
<td align="center">
<jsp:getProperty property="startStr" name="strBean"/>
</td>
</tr>
<tr>
<td>验证结果:</td>
<td align="right">
<jsp:getProperty property="check" name="strBean"/>
</td>
</tr>
</table>
</body>
1.PNG
2.PNG
3.PNG