Posts

Showing posts from June, 2017

Difference between two dates in java | Code Factory

import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.concurrent.TimeUnit; public class Main {   final static String[] dates = { "30-06-2014", "31-12-2014" }; public static void main(String[] args) { SimpleDateFormat myFormat = new SimpleDateFormat("dd-MM-yyyy"); String inputString1 = dates[0]; String inputString2 = dates[1]; try { Date date1 = myFormat.parse(inputString1); Date date2 = myFormat.parse(inputString2); long diff = date2.getTime() - date1.getTime(); System.out.println("Days: " + TimeUnit.DAYS.convert(diff, TimeUnit.MILLISECONDS)); } catch (ParseException e) { e.printStackTrace(); } } } Tags : Difference between two dates in java How to find the duration of difference between two dates in java Date

Spring Security Token Based Authentication | Code Factory

Image
Download code and jars :  Link. File : index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <center> <form action="sendData" method="post"> <table> <tr> <td>Username :</td> <td><input type="text" name="username"></td> </tr> <tr> <td>Username :</td> <td><input type="password" name="password"></td> </tr> <tr> <!-- TOCKEN --

Spring Security Custom Login Form XML | Code Factory

Image
Download code and jars :  Link. File : hello.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page session="false"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta name="_csrf" content="${_csrf.token}" /> <!-- default header name is X-CSRF-TOKEN --> <meta name="_csrf_header" content="${_csrf.headerName}" /> <title>Insert title here</title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <script type="text/javascript"> $(funct

Spring MVC + jQuery | Code Factory

Image
Download code and jars :  Link. File : Country.java package com.codeFactory.bean; public class Country { private int countryId; private String countryName; // Getters and setters. } File : Action.java package com.codeFactory.controller; import java.util.ArrayList; import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.codeFactory.bean.Country; @Controller public class Action { List<Country> allCountryList = new ArrayList<Country>(); public List<Country> getAllCountryList() { return allCountryList; } public void setAllCountryList(List<Country> allCountryList) { this.allCountryList = allCountryList; } @RequestMapping(value = "/getCountryList", method=RequestMethod.

How to set class=“active” in jQuery

Image
File : HTML file <body> <div class="container"> <ul class="nav nav-tabs"> <li id="parentMenuId"><a href="#parentMenu">Parent Menu</a></li> <li id="childMenuId"><a href="#childMenu">Child Menu</a></li> </ul> <div id="parentMenu"> <center> <div class="form-group"> <h1>parent menu</h1> </div> </center> </div> <div id="childMenu"> <center> <h1>child menu</h1> </center> </div> </div> </body> File : Scripting file <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>