[转自zzzhc’s blog] web.xml中定义url-pattern的时候,原以为可以使用正则表达式,老是报错.在servlet 2.4 specification中找到 SRV.11.2 Specification of MappingsIn theWeb application deployment descriptor, the following syntax is used to define mappings: • A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping. • A string beginning with a ‘*.’ prefix is used as an extension mapping. • A string containing only the ’/’ character indicates the “default” servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null. • All other strings are used for exact matches only.这规则真是够死的,郁闷. 但我还是想知道那样写的正则表达式对不对,有人回答出来就结帖。
<input type="text" id="txt"> <input type="button" onClick="test(document.getElementById('txt').value);" value="验证"> <script> function test(value){ var reg=/^(?!\/FCKEditor).+\.html$/g; if(reg.test(value)){ alert("验证通过!"); }else{ alert("输入内容不能以/FCKEditor开始,必须以.html结束!"); } } </script>
你试一下,我刚学的,不确定
web.xml中定义url-pattern的时候,原以为可以使用正则表达式,老是报错.在servlet 2.4 specification中找到 SRV.11.2 Specification of MappingsIn theWeb application deployment descriptor, the following syntax is used to define
mappings:
• A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used
for path mapping.
• A string beginning with a ‘*.’ prefix is used as an extension mapping.
• A string containing only the ’/’ character indicates the “default” servlet of
the application. In this case the servlet path is the request URI minus the context
path and the path info is null.
• All other strings are used for exact matches only.这规则真是够死的,郁闷.
但我还是想知道那样写的正则表达式对不对,有人回答出来就结帖。
<input type="button" onClick="test(document.getElementById('txt').value);" value="验证">
<script>
function test(value){
var reg=/^(?!\/FCKEditor).+\.html$/g;
if(reg.test(value)){
alert("验证通过!");
}else{
alert("输入内容不能以/FCKEditor开始,必须以.html结束!");
}
}
</script>