由于公司使用的是Struts1,所以从李老师的论坛下载了J2EE书中的第3章的pdf文件和代码
运行书中MVC示例:
部署MVC示例: 把李老师书中第3章代码中的MVC文件夹拉到Tomcat下就可以了,C:\Tomcat\webapps\mvc
启动Tomcat:双击运行C:\Tomcat\bin\startup.bat
运行:在IE地址栏里键入:http://localhost:8888/mvc/login.jsp
Sep9,2009
今天在公司无意中发现只要用IE打开.jsp文件就可以了. 突然明白了,其实和.html文件一样的?stupid
表单标签 <form>...</form>:
Please enter your username and password <form id="login" method="post" action="login" οnsubmit="return check(this);"> Username:<input type="text" name="username"/><br> Password:<input type="password" name="pass"/><br> <input type="submit" value="Login"/><br> </form>
参考李老师的"疯狂AJAX讲义"第3章"XHTML语言详解"P66
补充:
事件属性 onsubmit:
onSubmit is a scripting event that occurs when the user attempts to submit the form to the CGI.
the form onSubmit="return expression" can be used to cancel the submit if expression reture false.
this example
the form onSubmit="return expression" can be used to cancel the submit if expression reture false.
this example
<form...onsubmit="return check(this);">
tag uses a Javascript function to check the form data, If the expression
check(this); evaluates to false, the submit routine is cancelled; if it is true, the submit routine goes forward.
Let's look back the full code for our MVC login.jsp example. Here is the full code to do the check using Javascript function:
<script> function check(form) { if (form.username.value==null || form.username.value=="" ) { alert('Please enter you username'); return false; } else if(form.pass.value==null || form.pass.value=="" ) { alert('Please enter your password'); return false; } else { return true; } } </script>
好了,现在我们可以看出来了,如果你没有输入username 和 password',就会得到错误信息,并且返回false,login就不会被送出去验证的了