Saturday 25 April 2020

Enable telnet in Windows OS


1. Open "Control Panel" from start menu.
2. Open "Uninstall Programs".
3. Select the "Turn Windows features on or off " option.
4. Check the "Telnet Client" box.
5. Click "OK". A box will appear that says "Windows features" and "Searching for required        files". When complete, the Telnet client should be installed in Windows.



Self/Remote IP address ping command


Self/Remote IP address ping command.

Process:
1. Open the command prompt.
2. Syntax is "ping IP Address" then press enter
   A. Self Ping "ping 127.0.0.1" then press enter.
   B. Remote Ping "ping 10.10.1.100" then press enter.


3. Continues ping syntax "ping ip address -t" then press enter.
    Example: "ping 127.0.0.1 -t"



Wednesday 22 April 2020

Strping jdbcTemplate DB connection not closing or not getting new connections issue solution


Add below TransactionManger framework to resolve the DB connections issue.

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg>
<ref bean="dataSource" />
</constructor-arg>
</bean>

<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

Tuesday 21 April 2020

String contains special characters or not checking in Java?


By using below Java code you find out string contains a special character or not?
package com.javapages4all;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StrRegCheck {

public static void main(String[] args) {

String name="ra2ja2 3ABC 123";
Pattern special= Pattern.compile("[^a-z0-9 ]", Pattern.CASE_INSENSITIVE);
Matcher matcher = special.matcher(name);

if(matcher.find()){
//string contains special symbol/character
System.out.println("string having special character");
} else{
System.out.println("string don't have any special character");
}
}
}

Thursday 16 April 2020

JavaScript Countdown Timer Creation


<!DOCTYPE html>
<html>
<body>
<div>Registration closes in <span id="time">05:00</span> minutes!</div>

<script>
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);

minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;

display.textContent = minutes + ":" + seconds;

if (--timer < 0) {
timer = duration;
}
}, 1000);
}

var display = document.querySelector('#time');
var timeinseconds=60*5; //  60 seconds X 5 minutes
startTimer(timeinseconds, display);
</script>

</body>
</html>

Wednesday 15 April 2020

Getting System Date Time in Java Script



function getCurrentDateTime() {
var currentDate = new Date();

var dd = currentDate.getDate();
 var mm = currentDate.getMonth()+1; //January is 0!

var hh  = currentDate.getHours();
var min = currentDate.getMinutes();
var ss  = currentDate.getSeconds();

    if(dd<10){
        dd='0'+dd;
    }
    if(mm<10){
        mm='0'+mm;
    }
if(hh<10){
        hh='0'+hh;
    }
if(min<10){
        min='0'+min;
    }
    if(ss<10){
        ss='0'+ss;
    }

var datetime = currentDate.getFullYear() + "-" + mm + "-" + dd + " "+ hh + ":" + min + ":" + ss;

return datetime;
}

Saturday 11 April 2020

Batch script for getting windows KB Patch status(installed or not)

Batch script for getting windows KB patch status which is installed in system or not.

By using "systeminfo" command we can get the OS information.

Command : systeminfo | find "KB Name".

Batch script: 
1. create batch file "patchstatus.bat".
2. paste the below code in batch.

CALL systeminfo |findstr "KB2849697">>"C:\response.txt"
EXIT

3. save the file and run it. you can see the result in "response.txt" file if it found we will get response like below statement or if not installed it will show empty statement.

                           [01]: KB2849697

Batch script for getting windows OS name in windows.


Batch script for getting windows OS name in windows.

By using "systeminfo" command we can get the OS information.

Command : systeminfo | find "OS Name".

Batch script: 
1. create batch file "OSName.bat".
2. paste the below code in batch.

systeminfo | find "OS Name"

pause

3. save the file and run it. you can see the result in command prompt like below image.


Java Spring Quartz or CronTrigger loading multiple times Solution


Java Spring Quartz or CronTrigger loading multiple times with below Solution we can make load it once.

Spring Quartz or CronTrigger loading multiple times and its not problem with Quartz or CronTrigger configuration. this issue occurring because of the below "Web.xml" configuration issue .

1. Spring MVC Configuration(Web.xml).

 <servlet>
    <servlet-name>sampleapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>sampleapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

In Above Web.xml Spring configuration we have to observe/change the below things.

1. The servlet "sampleapp" will load "applicationContext.xml/sampleapp-servlet.xml" file.
2. And the listener ContextLoaderListener will loads "sampleapp-servlet.xml" again.

To fix the above issues do the below changes in web.xml

Fix: 1. change the servet-name "sampleapp" to some other name.
2. change the "applicationContext.xml" to "projectname-servlet.xml", 
i.e: "javapages" is my project name.

Please find the below spring configuration web.xml after above changes.

 <servlet>
    <servlet-name>testapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/javapages-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>testapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

Java Spring MVC beans loading twice Solution


Java Spring MVC beans loading twice with below Solution we can make load it once.


1. Spring MVC Configuration(Web.xml).


 <servlet>
    <servlet-name>sampleapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>sampleapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

In Above Web.xml Spring configuration we have to observe/change the below things.

1. The servlet "sampleapp" will load "applicationContext.xml/sampleapp-servlet.xml" file.
2. And the listener ContextLoaderListener will loads "sampleapp-servlet.xml" again.


To fix the above issues do the below changes in web.xml

Fix: 1. change the servet-name "sampleapp" to some other name.
2. change the "applicationContext.xml" to "projectname-servlet.xml", 
i.e: "javapages" is my project name.

Please find the below spring configuration web.xml after above changes.

 <servlet>
    <servlet-name>testapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/javapages-servlet.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>testapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>