ANGULARJS Form Validation Submission Example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.