Tuesday 31 March 2015

Create a Random String In PHP

$characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$randstring = '';
for ($i = 0; $i < 10; $i++) {
$randstring .= $characters[rand(0, strlen($characters))];
}
echo $randstring;

Generating a Log File In PHP

$log = "-----------Chinnayya Naidu Nalla's Application Accesed on".date("Y-m-d H:i:s"). "--------------".PHP_EOL.
"User: ".$_SERVER['REMOTE_ADDR'].' - '.date("F j, Y, g:i a").PHP_EOL.
"-------------------------".PHP_EOL;
file_put_contents('./log_'.date("j.n.Y").'.txt', $log, FILE_APPEND);





Place this code in your Php code it will generate a log file in your application. to achieve polymorphic nature place this in a function in a separate php file and include it. remember to create a function with a parameter to pass the log message to it Logging Code in a function with a parameter


function WriteLog($logmessage){
file_put_contents('./log_'.date("j.n.Y").'.txt', $logmessage, FILE_APPEND); }

Thursday 22 January 2015

Get the Parameters From the Form URL in JavaScript

function getSearchParameters() {
      var parameterstring = window.location.search.substr(1);
      return parameterstring != null && parameterstring != "" ? transformToAssocArray(parameterstring) : {};
}

function transformToAssocArray( parameterstring ) {
    var params = {};
    var prmarr = parameterstring.split("&");
    for ( var i = 0; i < prmarr.length; i++) {
        var tmparr = prmarr[i].split("=");
        params[tmparr[0]] = tmparr[1];
    }
    return params;
}

var params = getSearchParameters();
alert(params.code);


Test with any url having the Parameter

abc.html?code=adslkfjlaksjflsadfsadfsadfsaddfsafsdfasdf&abc=akjdha


Tuesday 13 January 2015

Blinking Your HTML Title

<script>
    function titlebar(val)
    {
    var speed = 1000;
    var position = val;
    var message1 = "Chinnayya Naidu Nalla - Software Developer ";

    var message2 = "Software Developer - Chinnayya Naidu Nalla"; 
    if(position == 0)    {
           message = message1;
           position = 1;
      } else if(pos == 1) {
          message = message2;
          position = 0;
      }
    document.title = message;
    timer = window.setTimeout("titlebar("+position +")",speed); }
    titlebar(0);

</script>

Sunday 11 January 2015

Animating Typography In HTML Pages

Css Code:

body{
  background: #000;
  padding-top: 10px;
}

p{
  color: lime;
  font-family: "Courier";
  font-size: 20px;
  margin: 10px 0 0 10px;
  white-space: nowrap;
  overflow: hidden;
  width: 30em;
  animation: type 4s steps(60, end);
}

p:nth-child(2){
  animation: type2 8s steps(60, end);
}

p a{
  color: lime;
  text-decoration: none;
}

span{
  animation: blink 1s infinite;
}

@keyframes type{
  from { width: 0; }
}

@keyframes type2{
  0%{width: 0;}
  50%{width: 0;}
  100%{ width: 100; }
}

@keyframes blink{
  to{opacity: .0;}
}

::selection{
  background: black;
}

HTML:


Develop a simple html page with content in a <p></p>  Paragraph tag

Saturday 3 January 2015

Calling Servlet Using a JQuery Ajax

First You need a JQuery Plugin i.e., jquery-1.8.2.js and add the jquery file to your project and your page

=================================================================

web.xml

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

  <servlet>
    <display-name>JqueryServlet</display-name>
    <servlet-name>JqueryServlet</servlet-name>
    <servlet-class>com.JqueryServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>JqueryServlet</servlet-name>
    <url-pattern>/JqueryServlet</url-pattern>
  </servlet-mapping>

 <welcome-file>index.jsp</welcome-file>


</web-app>


index.jsp



<html>
<head>
<title>AJAX JQuery in Java Web Application</title>

<script src="jquery-1.8.2.js"></script>

<script type="text/javascript">

$(document).ready(function(){
  $('#submitData').click(function(){
           sendData();
    });
});
function sendData(){
   var name = $('#username').val();
    var pwd = $('#password').val();
    $.ajax({
        type: "POST",
        url: "AjaxjqueryServlet",
        data: { userName : name , password : pwd }
      });
}
</script>
<style type="text/css">
.centered{
width:100%;
margin-left:auto;
margin-right:auto;
text-align:center;
}
</style>
</head>
<body>
<form method="post" >
<div class="centered">
<h2 style="text-align:center;">AJAX jquery Servlet in Java Web Application</h2>

 Name : <input type="text"  id="username"/><br/>
 Password :<input type="password"  id="password" /><br/>
 <input type="submit" value="Submit" id="submitData"/><br/>
</div>
</form>
</body>
</html>

Servlet: AjaxJqueryRequest



package com;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class JqueryServlet extends HttpServlet {
           
            private static final long serialVersionUID = 1L;
   
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {
                       
                          String userName = request.getParameter("userName");
                          System.out.println("userName:"+userName);
                         
                          String password = request.getParameter("password");
                          System.out.println("password:"+password );
           
            }
 }