Code Download: Https://files.cnblogs.com/files/xiandedanteng/angularjsFormSubmit.rar
Front Code:
<%@ Page ContentType="text/html; Charset=utf-8"%><%StringPath=Request.getcontextpath ();StringBasePath=Request.getscheme ()+"://"+Request.getservername ()+":"+Request.getserverport ()+Path+"/";%><!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en"><HTMLNg-app= "Notesapp"> <Head> <Basehref= "<%=basePath%>"> <title>My JSP ' index.jsp ' starting page</title> <Metahttp-equiv= "Pragma"content= "No-cache"> <Metahttp-equiv= "Cache-control"content= "No-cache"> <Metahttp-equiv= "Expires"content= "0"> <Metahttp-equiv= "keywords"content= "Keyword1,keyword2,keyword3"> <Metahttp-equiv= "description"content= "This is my page"> <MetaCharSet= "Utf-8"> <Scriptsrc= "Angular1.4.6.min.js"></Script> </Head> <BodyNg-controller= "Mainctrl as CTRL"> <formAction= "Verify"ID= "Form1">Name:<inputtype= "text"name= "Name"Ng-model= "Ctrl.username"/><BR/>You Typed:{{ctrl.username}}<BR/>pswd:<inputtype= "Password"name= "PSWD"Ng-model= "Ctrl.password"/><BR/>You typed:<spanNg-bind= "Ctrl.password"></span><BR/> <Buttontype= "button"Ng-click= "Ctrl.reset ()">Reset</Button> <!--Note that this does not write type= "button" will cause the form to submit - <Buttontype= "button"Ng-click= "Ctrl.submit ()">Submit</Button> </form> </Body></HTML><Scripttype= "Text/javascript"><!--Angular.module ('Notesapp', []). Controller ('Mainctrl',[function(){ var Self= This; Self.reset=function() {self.username=""; Self.password=""; }; //in Chrome Normal, self.username,self.password in Firxfox is undefinedSelf.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 ("user name or password not complete"); } alert (4); }; }]);// -</Script>
Background code:
Packagecom.test;ImportJavax.servlet.RequestDispatcher;Importjavax.servlet.ServletException;ImportJavax.servlet.http.HttpServlet;Importjavax.servlet.http.HttpServletRequest;ImportJavax.servlet.http.HttpServletResponse; Public classVerifyservletextendsHttpServlet {Private Static Final LongSerialversionuid = 56890894234786L; Public voidDoPost (httpservletrequest request, httpservletresponse response)throwsservletexception, 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 voiddoget (httpservletrequest request, httpservletresponse response)throwsservletexception, java.io.IOException {doPost (request, response); }}
ANGULARJS Form Validation Submission Example