Monday, March 29, 2010

Customize Javascript Confirm Box

Main.html
<html>
<head>
<title>
Customized Javascript Confirm Box Example
</title>
<script type="text/javascript">
function doDelete()
{
var returnVal=0;
if(window.showModalDialog)
{
returnVal=window.showModalDialog("YesOrNo.html","name","dialogWidth:455px;dialogHeight:140px");
}
if(returnVal==1)
{
alert("Deletion Succesfully Done");
// write your own functionality here
}
else
{
        alert("Deletion Cancelled");
// write your own functionality here
}
}
</script>
<body>
<font size="5">
<pre>
By clicking the bellow button you can observe customized javascript confirm dialog box
for deleting or some functionality what you require in your application.
                              

                                 <input type="button" value="Delete" onclick="doDelete();" style="font:20px"/>
</font>
</pre>

YesOrNo.html
<html>
<script>
function yesDelete(){
window.returnValue = 1; 
window.close();
return false;
}
function noDelete() {
window.returnValue = 0;  
window.close();
return false;
}
</script>
<body>
<div style="position:relative;left:0px;top:0px;background:#000066;color:#FFFFFF;font-size:20px;font-weight:bold;width:396px;height:25px;padding-left:38px;border-bottom:solid 2px #000000;">Confirm Delete...</div>
<blockquote style="font-size:18px;font-weight:bold;color:#FF0000;margin-top:50px;">Are you sure you wish to Delete this Record?</blockquote>
<div style="width:396px;text-align:center;">
<input type="button" value="    YES    " onclick="yesDelete();"  style="font-weight:bold;margin-right:10px;cursor:pointer;"><input type="button" value="     NO     " style="font-weight:bold;margin-left:10px;cursor:pointer;" onclick="noDelete();">
</div>
</body>
</html>

Both Main.html and YesOrNo.html files should be in the same folder.

Wednesday, March 17, 2010

Basic Servlet Structure

A servlet is a small Java program that runs within a Web server.Servlets receive and respond to requests from Web clients,usually across HTTP, the HyperText Transfer Protocol.

To write a Servlet Class we follow some basic steps.
1.Implement the Servlet interface available in javax.servlet package(javax.servlet.Servlet).
2.The acees speifier for your servlet class must be public.

Syntax:
 public class BasicServlet implements Servlet
 {
                   // Here we have to implement all methods in Servlet inteface.

  }

Methods in Servlet Inteface:

public void init(ServletConfig config) throws ServletException
{

}

By seeing the above method,we easily understand the init(ServletConfig config) always throws ServletException.So we have to handle when we implement our own Servlet class.

An Example to Implement init(ServletConfig config) method with some different syntax
Ex 1:
import javax.servlet.*;
public class SampleServlet implements Servlet
{
       public void init(ServletConfig config)
       {
                  try
                 {
                         //your code

                  }
                  catch(ServletException se)  { se.printStackTrace(); }
        }

// implement remaining all methods availabe in Servelt interface with some code to properly compile the java file
}

Ex 2:
import javax.servlet.*;
public class SampleServlet implements Servlet

{
       public void init(ServletConfig config) throws ServletException
       {

                    // your code
       }
// implement remaining all methods availabe in Servelt interface with some code to properly compile the java file

}

By seeing the above two examples,it is clear that when ever we write init(ServletConfig config) method ,it is not necessary to declare throws ServletException for inti(ServletConfig config) method.
    For informing the ServeltContainer to say initilization failed we are throwing ServletException to not to put  Servelt Object in service,instead of explicity handling ServletException using try/catch blocks.If we are handling exception explicity how to inform the container about init() fail.Is there any solution in this case.Think your self.

Monday, March 15, 2010

Software Jobs

visit the following links to know about the software jobs
1   http://www.javaken.com/
2.  http://www.presentjobs.com/
3.  http://www.jobconsultancy.com/

Disable Mouse Right Click in IE ,Firefox & Google Chrome

<script type="text/javascript">
<!-- Disable Right Click in IE & Firefox -->
var message="";


function clickIE()

{if (document.all)
{(message);return false;}}

function clickNS(e) {
if
(document.layers||(document.getElementById&&!document.all))
{
if (e.which==2||e.which==3) {(message);return false;}}}
if (document.layers)
{document.captureEvents(Event.MOUSEDOWN);document.  onmousedown=clickNS;}
else
{document.onmouseup=clickNS;document.oncontextmenu  =clickIE;}

document.oncontextmenu=new Function("return false")
</script>

Sunday, March 7, 2010

javascript email validation example

This is the customized javascript email validation , based upon your requirement,you can be able to customize the validation with simple code.

function ValEmailId(arg)
{
    var email=arg;     
    var f=0;
      if (! allValidChars(email)) { 
    f=1;
      }    
      else if (email.indexOf(".") < 1)  { 
       f=1;
      }
      else if (email.indexOf("_") < 1 && email.indexOf("_")!=-1) { 
       f=1;              
      }
      else if (email.indexOf("-") < 1 && email.indexOf("-")!=-1) {
       f=1;
      }
      else if (email.indexOf("@") < 1) {
       f=1;
      }
      else if (email.indexOf(".@")>=0 || email.indexOf("_@")>=0 || email.indexOf("-@")>=0 ||  email.indexOf("@@")>=0 || email.indexOf("--")>=0 || email.indexOf("__")>=0 || email.indexOf("-_")>=0 || email.indexOf("_-")>=0) {
           f=1;
       }
      else if(email.indexOf("@.")>=0 || email.indexOf("@_")>=0 || email.indexOf("@-")>=0)
      {
          f=1;
      }             
      else if (email.lastIndexOf(".") <= email.indexOf("@")) { 
       f=1;
      }
      else if (email.indexOf("@") == email.length-1) { 
       f=1;
      }
      else if (email.indexOf("..") >=0) {
       f=1;
      }
      else if (email.indexOf(".") == email.length-1) { 
       f=1;          
      }
   if(f==1)                      
   {
       alert("Please Enter Valid Email");
       document.forms[0].emailId.focus();
       return false;
   }        
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)             
      continue;
    parsed = false;
    break;
  }        
  return parsed;
}