代码下载:https://files.cnblogs.com/files/xiandedanteng/angularjsFormSubmit.rar

前台代码:

<%@ page contentType="text/html; charset=UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html ng-app="notesApp">
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</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">
    <meta charset="utf-8">
    <script src="angular1.4.6.min.js"></script>
  </head>

  <body ng-controller="MainCtrl as ctrl">
    <form action="Verify" id="form1">
          Name:<input type="text" name="name" ng-model="ctrl.username"/><br/>
          You typed:{{ctrl.username}}<br/>
          Pswd:<input type="password" name="pswd"  ng-model="ctrl.password"/><br/>
          You typed:<span ng-bind="ctrl.password"></span><br/>
          <button type="button" ng-click="ctrl.reset()">Reset</button> <!-- 注意这里不写 type="button" 会导致表单提交-->
          <button type="button" ng-click="ctrl.submit()">Submit</button>

    </form>
  </body>
</html>

<script type="text/javascript">
<!--
    angular.module('notesApp',[])
     .controller('MainCtrl',[function(){
       var self=this;

       self.reset=function(){
               self.username="";
               self.password="";
       };

       // 在Chrome正常,在FirxFox中self.username,self.password是undefined
       self.submit=function(){
               alert("self.username="+self.username);
               alert("self.password="+self.password);
               if(self.username!="" && self.password!=""){
                   alert(2);
                   document.forms[0].submit();
               }else{
                   alert(3);
                   alert("用户名或密码不全");
               }
               alert(4);

       };

     }]);
//-->
</script>

后台代码:

package com.test;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class VerifyServlet extends HttpServlet {
    private static final long serialVersionUID = 56890894234786L;

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, java.io.IOException {
        request.setCharacterEncoding("UTF-8");

        String name=request.getParameter("name");
        String pswd=request.getParameter("pswd");

        request.setAttribute("name", name);
        System.out.println("name="+name);
        request.setAttribute("pswd", pswd);
        System.out.println("pswd="+pswd);

        RequestDispatcher dispatcher = request.getRequestDispatcher("result.jsp");
        dispatcher.forward(request, response);
        return;
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, java.io.IOException {
        doPost(request, response);
    }
}

AngularJS的表单验证提交示例的更多相关文章

  1. 表单验证提交——submit与button

    之前做东西接触过表单验证提交,但是都是为了完成工作,做完就做完了,没有注过表单验证提交有几种方法,各方法都有啥区别.今天瞎折腾了一下,对他们研究了一下,如下是我个人的理解: submit: 从字面上看 ...

  2. 基于angularJS的表单验证练习

    今天看了一下angularJS的表单验证,看的有点云里雾里(也有可能是雾霾吸多了),于是做了一个小练习来巩固一下. html: <div ng-controller="Aaa" ...

  3. 第一百五十四节,封装库--JavaScript,表单验证--提交验证

    封装库--JavaScript,表单验证--提交验证 将表单的所有必填项,做一个判断函数,填写正确时返回布尔值 最后在提交时,判断每一项是否正确,全部正确才可以 提交 html <div id= ...

  4. 【AngularJs】---表单验证

    1. 必填项 验证某个表单输入是否已填写,只要在输入字段元素上添加HTML5标记required即可: <input type="text" required /> 2 ...

  5. angularJS 过滤器 表单验证

    过滤器1.filter的作用就是接收一个输入,通过某个规则进行处理,然后返回处理后的结果,主要用于数据的格式化.2.内置过滤器(1)Currency(货币)将一个数值格式化为货币格式,默认为$(2)D ...

  6. AngularJS 的表单验证

    最近开始学习angularjs,学到表单验证的时候发现有必要学习下大神的好文章: 转:http://www.oschina.net/translate/angularjs-form-validatio ...

  7. angularjs的表单验证

    angularjs内置了常用的表单验证指令,比如min,require等.下面是演示: <!DOCTYPE html> <html> <head> <meta ...

  8. AngularJS复习------表单验证

    在AngularJS中能够将HTML5表单验证功能同自己的验证指令结合起来使用,这里介绍使用的核心功能. 使用表单验证,首先要确保表单的每个控件都有name属性 如果想要屏蔽浏览器对表单的默认验证行为 ...

  9. MVC身份验证.MVC过滤器.MVC6关键字Task,Async.前端模拟表单验证,提交.自定义匿名集合.Edge导出到Excel.BootstrapTree树状菜单的全选和反选.bootstrap可搜索可多选可全选下拉框

    1.MVC身份验证. 有两种方式.一个是传统的所有控制器继承自定义Control,然后再里面用MVC的过滤器拦截.所以每次网站的后台被访问时.就会先走入拦截器.进行前端和后端的验证 一个是利用(MVC ...

随机推荐

  1. loj2012 「SCOI2016」背单词

    -- #include <algorithm> #include <iostream> #include <cstring> #include <cstdio ...

  2. luogu2951 noip2017 小凯的疑惑

    在考场上我们可以打表发现规律是 $ ab-a-b $ .下面给出证明(看的网上的). 若有正数 $ x $ 不能被 $ a $ , $ b $ 组合出,假设 $ a>b $ ,则存在 \[ x= ...

  3. luogu2394 yyy loves Chemistry I

    练习 #include <iostream> #include <cstdio> using namespace std; long double a; int main(){ ...

  4. java append方法

    JAVA 中 Stringbuffer 有append()方法  Stringbuffer其实是动态字符串数组  append()是往动态字符串数组添加,跟“xxxx”+“yyyy”相当那个‘+’号  ...

  5. oracle整体结构-内存结构、物理结构、逻辑结构、进程

    Oracle的体系结构大体上分为两部分:Instance(实例)和Database(数据库). Instance(实例) :在Oracle Instance中主要包含了SGA以及一些进程(例如:PMO ...

  6. MongoDB 3.6 安装详解

    在ubuntu和多数linux发行版的包安装源中MongoDB默认的版本是2.4,但2.4所使用的存储引擎不支持collecitons级别的锁,只支持database级别的,所以在开发中2.4版本的m ...

  7. js 获取data-属性值

    ].getAttribute('data-price'); 注意 document.getElementsByClassName('1pc_price')后面有[0],不然会报错.

  8. Leetcode 430.扁平化多级双向链表

    扁平化多级双向链表 您将获得一个双向链表,除了下一个和前一个指针之外,它还有一个子指针,可能指向单独的双向链表.这些子列表可能有一个或多个自己的子项,依此类推,生成多级数据结构,如下面的示例所示. 扁 ...

  9. Thanks for your encourage!

    将近三个月的学习,我的努力换回了代表荣誉的小黄衫,这令我很开心啊...我想是不是要写点什么来表达自己的心情呢=,=  于是就有了以下文字ahhhhhh... 学习心得: (1)学习中总会有失败和成功, ...

  10. Linux定时任务Crontab命令详解 转

      linux 系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个系统服务是默认启动的.另 外, 由于使用者自己也可以设置计划任务,所 ...