JavaWeb-两种业务逻辑的判断方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41690324/article/details/83546582
第一种,使用html的方式判断,如

<form action="action.jsp" method="post">

	<!-- 通过正则表达式决定输入的字符 -->
	用户名:<input pattern="[a-zA-Z]{3,10}" name="username">(只能由字母组成,长度在3-10位之间)    
    <br />
	密码:<input pattern="[a-zA-Z0-9]{6,12}" type="password" name="password">(只能由字母数字组    
    成,长度在6-15位之间)<br />
	<input type="submit"><br>

</form>
第二种,使用java的方式判断,可以写在jsp页面中
使用String的matches(String regex)方法.

//判断是否符合业务逻辑
if (username.matches("[a-zA-Z0-9]{6,12}")&& password.matches("[a-zA-Z0-9]{6,12}")) {			
	out.print("业务逻辑正确");
} else {			
	out.print("业务逻辑错误");
}

猜你喜欢

转载自blog.csdn.net/qq_41690324/article/details/83546582
今日推荐