加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJS for login

发布时间:2020-12-17 10:01:24 所属栏目:安全 来源:网络整理
导读:web.xml ?xml version="1.0" encoding="UTF-8"?web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">


  <servlet>  
         <servlet-name>dispatcherServlet</servlet-name>  
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
         <load-on-startup>1</load-on-startup>  
   </servlet>  

   <servlet-mapping>  
         <servlet-name>dispatcherServlet</servlet-name>  
         <url-pattern>/</url-pattern>  
   </servlet-mapping>  
   

</web-app>
dispatcherServlet-servlet.xml
<?xml version="1.0" encoding= "UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="
            http://www.springframework.org/schema/mvc 
             http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
            http://www.springframework.org/schema/beans 
            http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
            http://www.springframework.org/schema/context 
            http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <mvc:annotation-driven/>
  <mvc:default-servlet-handler/>

  <context:component-scan base-package="com.liyang"/>    
  
  <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
     <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
     <property name="prefix" value="/WEB-INF/"></property>
     <property name="suffix" value=".html"></property>
   </bean>      
  
   
</beans>

index.html
<head>
      <meta charset="utf-8">
      <title>AngularJS  依赖注入</title>
          <script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

   <div ng-app="myApp" ng-controller = "loginCtrl">    
       <form>
            <input ng-model = "user.name" />  <br>
            <input ng-model = "user.pass" />  <br>
            
            <button ng-click = "login(user)" > LogIn</button>
               
       </form> 
            <p> {{res}}</p> 
    </div>
    
    
    <script>
		    var app = angular.module('myApp',[]);
		    app.controller('loginCtrl',function($scope,$http) {
		    	 $scope.res = "登陆测试" ;
		    	 
		    	 $scope.login = function(user) {
		    		$http.get("admin/login?username=" + user.name + "&password=" + user.pass) 
		    		     .success(function(res){
		    		    	   $scope.res = res.data ;
		    		     })    
		    	}
		     });
       
    </script>
    
</body>
</html>


package com.liyang.view;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class Web {

	@RequestMapping(value = "index")
	public String index(){
		return "index" ;
	}
}


package com.liyang.controller;

import java.util.HashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.google.gson.Gson;


@Controller
@RequestMapping(value = "/admin")
public class AdminController {   
	
	@RequestMapping(value = "login")
	@ResponseBody
	public String login(
		   @RequestParam(value = "username") String username,@RequestParam(value = "password") String password )
	{
		  Map<String,String> res = new HashMap<String,String>() ;
		  if(username.equals("a") && password.equals("a")){
			  res.put("data","yes") ;
		  }
		  else res.put("data","wrong") ;
		  
		  Gson gson = new Gson() ;
		  return gson.toJson(res)    ;	  
	}

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读