請服用
http://www.sergiy.ca/how-to-iterate-over-a-map-in-java
//get current user
String currentUser = AuthenticationUtil.getFullyAuthenticatedUser();
String fakeUser = "IAMBIGD";
LOGGER.debug("currentUser:" + currentUser);
if (currentUser == null || !currentUser.equals(fakeUser)) {
// AuthenticationUtil.setCurrentUser(username);
//set impersonate
AuthenticationUtil.setFullyAuthenticatedUser(fakeUser);
}
app.directive('validFile',function(){
return {
require:'ngModel',
link:function(scope,el,attrs,ngModel){
//change event is fired when file is selected
el.bind('change',function(){
scope.$apply(function(){
ngModel.$setViewValue(el.val());
ngModel.$render();
});
});
}
}
});
Input is valid: {{myForm.userUpload.$valid}} Selected file: {{filename}}
//設定某個物件被選擇
ng-class="{true: 'table-row-selected', false: ''}[product.selected]"
//取得被選擇的使用者數量
$scope.getSelectedUsers = function() {
var selectedObjs = $filter("filter")($scope.userList, {
selected: true
})
return selectedObjs;
};
//html ng-repeat="folder in parentFolders.slice().reverse()
$location.path('/login');
$window.open('http://www.yahoo.com.tw');
$scope.userList.splice($index, 1);//移除使用者清單內的某一用戶
app.run(['$http', function($http) {
// The $http service will automatically add certain HTTP headers to all requests. These defaults can be fully configured by accessing the $httpProvider.defaults.headers configuration object, which currently contains this default configuration:
// $httpProvider.defaults.headers.common (headers that are common for all requests):
// Accept: application/json, text/plain, * / *
// $httpProvider.defaults.headers.post: (header defaults for POST requests)
// Content-Type: application/json
// $httpProvider.defaults.headers.put (header defaults for PUT requests)
// Content-Type: application/json
$http.defaults.headers.common['Content-Type'] = 'application/json';
}])
$scope.$watch('form', function(newVal, oldVal){
console.log('changed');
}, true);
app.run(['$templateCache',function($templateCache){
$templateCache.removeAll();
}]);
import urllib.request,os,hashlib; h = '7183a2d3e96f11eeadd761d777e62404' + 'e330c659d4bb41d3bdf022e94cab3cd0'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://sublime.wbond.net/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)
Filter and there are great explanation and example in StackOverflow Servlet-Filter wiki.needsAuthenticationmethod):@WebFilter("/*")
public class LoginFilter implements Filter {
@Override
public void init(FilterConfig config)
throws ServletException {
// If you have any in web.xml, then you could get them
// here by config.getInitParameter("name") and assign it as field.
}
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
String requestPath = httpServletRequest.getRequestURI();
if (needsAuthentication(requestPath) ||
session == null ||
session.getAttribute("user") == null) { // change "user" for the session attribute you have defined
response.sendRedirect(request.getContextPath() + "/login"); // No logged-in user found, so redirect to login page.
} else {
chain.doFilter(req, res); // Logged-in user found, so just continue request.
}
}
@Override
public void destroy() {
// If you have assigned any expensive resources as field of
// this Filter class, then you could clean/close them here.
}
//basic validation of pages that do not require authentication
private boolean needsAuthentication(String url) {
String[] validNonAuthenticationUrls =
{ "Login.jsp", "Register.jsp" };
for(String validUrl : validNonAuthenticationUrls) {
if (url.endsWith(validUrl)) {
return false;
}
}
return true;
}
}
app and then change the web filter to@WebFilter("/app/*")
needsAuthentication method from the filter.module.directive('selectOnClick', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
element.on('click', function () {
this.select();
});
}
};
});
ng-model was introduced in ui-bootstrap-tpls-0.11.0.js, as explained in thechangelog:Bothpaginationandpagerare now integrated withngModelController.
*pageis replaced fromng-model.
*on-select-pageis removed sinceng-changecan now be used.
<alert ng-repeat="alert in alerts"
type="alert.type"
close="alert.close($index)">{{alert.msg}}</alert>
app.factory('AlertService', ['$rootScope', '$timeout', '$log',
function($rootScope, $timeout, $log) {
var alertService = this;
$rootScope.alerts = [];
return alertService = {
add: function(type, msg, timeout) {
$rootScope.alerts.push({
type: type,
msg: msg,
close: function() {
return alertService.closeAlert(this);
}
});
if(typeof(timeout) == 'undefined'){
timeout = 5000;
}
if (timeout) {
$timeout(function() {
alertService.closeAlert(this);
}, timeout);
}
},
closeAlert: function(alert) {
$log.log(alert);
return this.closeAlertIdx($rootScope.alerts.indexOf(alert));
},
closeAlertIdx: function(index) {
return $rootScope.alerts.splice(index, 1);
},
clear: function(){
$rootScope.alerts = [];
}
};
}
])
angular.module('myApp.controllers').controller('LoginCtrl', ['$rootScope','$scope', '$log', 'AuthService', 'AlertService','$location',
function($rootScope, $scope, $log, AuthService, AlertService, $location) {
$log.log('load login page');
$scope.login = function(credentials) {
$log.log('press login button');
$log.log(credentials);
AuthService.login(
credentials, function(data, status, headers, config) {
$log.log('success to call login');
$log.log(data);
if (data.status == 200) {
$log.log('go to default users page');
//go to home
$location.path('/users');
}else if (data.status == 500){
AlertService.add('danger','不正確的帳號或密碼');
}
}, function(data, status, headers, config) {
$log.log('fail to call login');
AlertService.add('danger','伺服器發生錯誤,請重新再試');
});
};
}
]);
$broadcast -- dispatches the event downwards to all child scopes,$emit -- dispatches the event upwards through the scope hierarchy.firstCtrl is parent of the secondCtrl scope, your code should work by replacing $emit by $broadcast in firstCtrl:function firstCtrl($scope){
$scope.$broadcast('someEvent', [1,2,3]);
}
function secondCtrl($scope){
$scope.$on('someEvent', function(event, mass) {console.log(mass)});
}
$rootScope into the controller and broadcast the event to all child scopes (i.e. also secondCtrl).function firstCtrl($rootScope){
$rootScope.$broadcast('someEvent', [1,2,3]);
}
$scope.$emit. If scope of firstCtrl is parent of the secondCtrl scope:function firstCtrl($scope){
$scope.$on('someEvent', function(event, data) { console.log(data); });
}
function secondCtrl($scope){
$scope.$emit('someEvent', [1,2,3]);
}