AngularJS的表單驗證提交樣本

來源:互聯網
上載者:User

標籤:tle   htm   div   dex   head   使用者名稱   key   angular   w3c   

代碼下載: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的表單驗證提交樣本

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.