Sometimes you need advice, Ask a teacher to solve your problems.

Sometimes you need advice, Ask a teacher to solve your problems.

Make a Difference with education, and be the best.

Make a Difference with education, and be the best.

Latest Posts

Friday 2 August 2019

How to play videos in AngularJs just right of your table action play button

DashZin
HTMP Page 

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div class="row">
<div class="col-md-6">
  <h2>Basic Table</h2>         
  <table class="table">
    <thead>
      <tr>
        <th>Firstname</th>
        <th>Lastname</th>
        <th>Action</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>John</td>
        <td>Doe</td>
        <td><button ng-click="playVideo(1)">Test</button></td>
      </tr>
      <tr>
        <td>Mary</td>
        <td>Moe</td>
        <td><a ng-click="playVideo(2)">Test</a></td>
      </tr>
      <tr>
        <td>July</td>
        <td>Dooley</td>
        <td>july@example.com</td>
      </tr>
    </tbody>
  </table>

</div>

<div class="col-md-6">
<h3>View Content</h3>
<ui-view>
<ion-content style="background-color:white ; margin-top:0px;" ng-init="playVideo()" >
<div >
   <video controls  style="margin-left: 10%"; width="300";height="400"></video>
</div>
</ion_content>
</ui-view>
</div>
</div>
</body>
</html>


Js File 

Module creating:-

Angular.module('app' ,,[]);

Configure UI-Router:-

app.config(function($stateProvider,$urlRouterProvider) {
$urlRouterProvider.otherwise('/nav');
    $stateProvider
    .state('nav.multipleview', {
        url: '/multipleview',
        templateUrl: 'App/multiple-view/multipleview.html',
        controller:'multipleViewController'
     })
});

Controller creating:-
app.controller('multipleViewController',['appService','$scope','$rootScope',function(appService,$scope,$rootScope){

$scope.playVideo = function(id) {
alert(id);
var vidURL = "http://clips.vorwaerts-gmbh.de/VfE_html5.mp4";
var myVideo = document.getElementsByTagName('video')[0];
myVideo.src = vidURL;
myVideo.load();
myVideo.play();
}

}]);


Thursday 1 August 2019

Timer with stop ans start button in JavaScripts

DashZin
HTML Code : 

    <input type="button" name="btn" id='btn' value="Start" onclick="to_start()";>
    <br><br>
   <div id=n1 style="z-index: 2; position: relative; right: 0px; top: 10px; background-color: #00cc33;
    width: 100px; padding: 10px; color: white; font-size:20px; border: #0000cc 2px dashed; "> </div>     <br>
    <input type="button" name="btn" id='btn' value="Start" onclick="stop()";>



JavaScripts Code : 

    <script language=javascript>
   var h=0;
   var m=0;
   var s=0;
   function to_start(){
   tm=window.setInterval('disp()',1000);
   }

   function stop(){
   window.clearInterval(tm); // stop the timer
   h=0;
   m=0;
   s =0;
   }


   function disp(){
   // Format the output by adding 0 if it is single digit //
   if(s<10){var s1='0' + s;}
   else{var s1=s;}
   if(m<10){var m1='0' + m;}
   else{var m1=m;}
   if(h<10){var h1='0' + h;}
   else{var h1=h;}
   // Display the output //
   str= h1 + ':' + m1 +':' + s1 ;
   var time=document.getElementById('n1').innerHTML=str;
   // Calculate the stop watch //
   if(s<59){
   s=s+1;
   }else{
   s=0;
   m=m+1;
   if(m==60){
   m=0;
   h=h+1;
   } // end if  m ==60
   }// end if else s < 59
   // end of calculation for next display

   }
   </script>


Wednesday 31 July 2019

tree view

DashZin

<!DOCTYPE html>
<html>
<head>
    <base href="https://demos.telerik.com/kendo-ui/treeview/checkboxes">
    <style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
    <title></title>
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.common-material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.material.min.css" />
    <link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.619/styles/kendo.material.mobile.min.css" />

    <script src="https://kendo.cdn.telerik.com/2019.2.619/js/jquery.min.js"></script>
    <script src="https://kendo.cdn.telerik.com/2019.2.619/js/kendo.all.min.js"></script>
   

</head>
<body>
<div id="example">

    <div class="demo-section k-content">
        <div>
            <h4>Check nodes</h4>
            <div id="treeview"></div>
        </div>
        <div style="padding-top: 2em;">
            <h4>Status</h4>
            <p id="result">No nodes checked.</p>
        </div>
    </div>

    <script>
        $("#treeview").kendoTreeView({
            checkboxes: {
                checkChildren: true
            },

            check: onCheck,

            dataSource: [{
                id: 1, text: "Ranchi", expanded: true, items: [
                  { id: 2, text: "a" },
                            { id: 3, text: "b" },
                            { id: 4, text: "c"}
                 
                ]
            }]
        });

        // function that gathers IDs of checked nodes
        function checkedNodeIds(nodes, checkedNodes) {
            for (var i = 0; i < nodes.length; i++) {
                if (nodes[i].checked) {
                    checkedNodes.push(nodes[i].id);
                }

                if (nodes[i].hasChildren) {
                    checkedNodeIds(nodes[i].children.view(), checkedNodes);
                }
            }
        }

        // show checked node IDs on datasource change
        function onCheck() {
            var checkedNodes = [],
                treeView = $("#treeview").data("kendoTreeView"),
                message;

            checkedNodeIds(treeView.dataSource.view(), checkedNodes);

            if (checkedNodes.length > 0) {
                message = "IDs of checked nodes: " + checkedNodes.join(",");
            } else {
                message = "No nodes checked.";
            }

            $("#result").html(message);
        }
    </script>

    <style>
        #treeview .k-sprite {
            background-image: url("../content/web/treeview/coloricons-sprite.png");
        }

        .rootfolder { background-position: 0 0; }
        .folder     { background-position: 0 -16px; }
        .pdf        { background-position: 0 -32px; }
        .html       { background-position: 0 -48px; }
        .image      { background-position: 0 -64px; }
    </style>

</div>


</body>
</html>

AngularJS timer with start and stop button

DashZin
//............timer...........................
   //timer with interval
   $scope.timerWithInterval = 0;
   $scope.total;
    $scope.startTimerWithInterval = function() {
     $scope.timerWithInterval = 0;
     if($scope.myInterval){
       $interval.cancel($scope.myInterval);
     }
     $scope.onInterval = function(){
         $scope.timerWithInterval++;
         $scope.total=$scope.timerWithInterval;
     }
     $scope.myInterval = $interval($scope.onInterval,1000);
   
     console.log("timerWithInterval",$scope.myInterval);
   };
 
   $scope.resetTimerWithInterval = function(){
   var da=$filter('date')($scope.total,'hh:mm:ss');
   console.log("$scope.da",$scope.total | hhmmss);
   console.log("$scope.total",$scope.total);
     $scope.timerWithInterval = 0;
     $interval.cancel($scope.myInterval);
   }



}]);
//....should outside of the controller..
app.filter('hhmmss', function () {
  return function (time) {
    var sec_num = parseInt(time, 10); // don't forget the second param
    var hours   = Math.floor(sec_num / 3600);
    var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
    var seconds = sec_num - (hours * 3600) - (minutes * 60);

    if (hours   < 10) {hours   = "0"+hours;}
    if (minutes < 10) {minutes = "0"+minutes;}
    if (seconds < 10) {seconds = "0"+seconds;}
    var time    = hours+':'+minutes+':'+seconds;
    return time;
  }
});


....html to start and stop timer
  <p ng-bind="timerWithInterval">Timer with interval: {{timerWithInterval | hhmmss}}</p>
  <button ng-click="startTimerWithInterval()">Start Timer</button>
  <button ng-click="resetTimerWithInterval()">reset tiemr</button>


Tuesday 28 August 2018

Servlet API

DashZin

Servlet API consists of two important packages that encapsulates all the important classes and interface, namely :
ü  javax.servlet : The javax.servlet package contains many interfaces and classes that are used by the servlet or web container. These are not specific to any protocol.
ü  javax.servlet.http : The javax.servlet.http package contains interfaces and classes that are responsible for http requests only.
 Some Important Classes And Interface of javax.servlet

INTERFACES
CLASSES
Servlet
ServletInputStream
ServletContext
ServletOutputStream
ServletConfig
ServletRequestWrapper
ServletRequest
ServletResponseWrapper
ServletResponse
ServletRequestEvent
ServletContextListener
ServletContextEvent
RequestDispatcher
ServletRequestAttributeEvent
SingleThreadModel
ServletContextAttributeEvent
Filter
ServletException
FilterConfig
UnavailableException
FilterChain
GenericServlet
ServletRequestListener

  Some Important Classes And Interface of javax.servlet
CLASSES and INTERFACES
HttpServlet
HttpServletRequest
HttpServletResponse
HttpSessionAttributeListener
HttpSession
HttpSessionListener
Cookie
HttpSessionEvent






Servlet Interface

DashZin
Servlet interface provides common behaviour to all the servlets.
Servlet interface needs to be implemented for creating any servlet (either directly or indirectly). It provides 3 life cycle methods that are used to initialize the servlet, to service the requests, and to destroy the servlet and 2 non-life cycle methods.

Servlet Interface Method
There are 5 methods in Servlet interface. The init, service and destroy are the life cycle methods of servlet. These are invoked by the web container.
      
    1. void destroy(): This method is called by Servlet container at the end       of servlet life cycle. Unlike service() method that gets called multiple times  during life cycle, this method is called only once by Servlet container during  the complete life cycle. Once destroy() method is called the servlet container does not call the service() method for that servlet.
    2. void init(ServletConfig config): When Servlet container starts up (that happens when the web server starts up) it loads all the servlets and instantiates them. After this init() method gets called for each instantiated servlet, this method initializes the servlet.

      3. void service(ServletRequest req, ServletResponse res): This is the only method that is called multiple times during servlet life cycle. This methods serves the client request, it is called every time the server receives a request.

     4. ServletConfig getServletConfig(): Returns a ServletConfig object, which contains initialization and startup parameters for this servlet.

    5. java.lang.String getServletInfo(): Returns information about the servlet, such as author, version, and copyright.


Servlet Example by implementing Servlet interface

Let's see the simple example of servlet by implementing the servlet interface.
File : Dashzin.java
       
        import java.io.*;  
        import javax.servlet.*;  
  
        public class Dashzin implements Servlet{  
        ServletConfig config=null;  
  
       public void init(ServletConfig config){  
       this.config=config;  
       System.out.println("servlet is initialized");  
       }  
  
       public void service(ServletRequest req,ServletResponse res)  
       throws IOException,ServletException{  
  
      res.setContentType("text/html");  
  
      PrintWriter out=res.getWriter();  
       out.print("<html><body>");  
        out.print("<b>hello simple servlet using servlet interface</b>");  
       out.print("</body></html>");  
  
        }  
        public void destroy(){
        System.out.println("servlet is destroyed");
        }  
        public ServletConfig getServletConfig(){
       return config;
       }  
        public String getServletInfo(){
        return "Welcome to Dashzin Servlet Blog";
       }  
       }  










Wednesday 1 August 2018

GenericServlet Class

DashZin
The GenericServlet class implements the Servlet and ServletConfig interfaces. Since service () method is declared as an abstract method in GenericServlet class, it is an abstract class. The class extending this class must implement the service () method. It is used to create servlets which are protocol independent.
To understand the creation of servlets using the GenericServlet class, lets us consider a simple program given here. For this, two files will be required; one .java file in which servlet is defined and another. html file containing code for web page.
Pros of using Generic Servlet:1. Generic Servlet is easier to write
2. Has simple lifecycle methods
3. To write Generic Servlet you just need to extend javax.servlet.GenericServlet      and override the service() method
Cons of using Generic Servlet:Working with Generic Servlet is not that easy because we don’t have convenience methods such as doGet(), doPost(), doHead() etc in Generic Servlet that we can use in Http Servlet.
In Http Servlet we need to override particular convenience method for particular request, for example if you need to get information then override doGet(), if you want to send information to server override doPost(). However in Generic Servlet we only override service() method for each type of request which is cumbersome.

Methods of GenericServlet class

There are many methods in GenericServlet class. They are as follows:
  1. public void init(ServletConfig config) is used to initialize the servlet.
  2. public abstract void service(ServletRequest request, ServletResponse response) provides service for the incoming request. It is invoked at each time when user requests for a servlet.
  3. public void destroy() is invoked only once throughout the life cycle and indicates that servlet is being destroyed.
  4. public ServletConfig getServletConfig() returns the object of ServletConfig.
  5. public String getServletInfo() returns information about servlet such as writer, copyright, version etc.
  6. public void init() it is a convenient method for the servlet programmers, now there is no need to call super.init(config)
  7. public ServletContext getServletContext() returns the object of ServletContext.
  8. public String getInitParameter(String name) returns the parameter value for the given parameter name.
  9. public Enumeration getInitParameterNames() returns all the parameters defined in the web.xml file.
  10. public String getServletName() returns the name of the servlet object.
  11. public void log(String msg) writes the given message in the servlet log file.
  12. public void log(String msg,Throwable t) writes the explanatory message in the servlet log file and a stack trace.
Example of GenericServlet Class
This servlet program is used to print "Hello World" on client browser using GenericServlet class.
HelloWorld.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * This servlet program is used to print "Hello World" on
 * client browser using GenericServlet class.
 * @author javawithease
 */
public class HelloWorld extends GenericServlet {
    private static final long serialVersionUID = 1L;

    //no-argument constructor.
    public HelloWorld() {

    }

    @Override
    public void service(ServletRequest request, ServletResponse response)
                               throws ServletException, IOException {
          response.setContentType("text/html");
          PrintWriter out = response.getWriter();

        out.println("<h1>Hello World example using" +
                              " GenericServlet class.</h1>");
        out.close();                
    }
}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 
          <servlet>
                    <servlet-name>HelloWorld</servlet-name>
                    <servlet-class>
                       com.javawithease.business.HelloWorld
                    </servlet-class>
          </servlet>
 
          <servlet-mapping>
                    <servlet-name>HelloWorld</servlet-name>
                    <url-pattern>/HelloWorld</url-pattern>
          </servlet-mapping>
 
</web-app>


Output










Our Team

  • Dashrath YadavB.Tech / Computers
  • Dashrath YadavB.Tech / Computers