Wednesday, June 29, 2011

How to get clipboard data from webpage.

How to get clipboard data from webpage.
--------------------------------------------------------

Just put all the files(amitcert.crt, GetClipBoardData.html and GetClipBoardData.jar)
in the web directory.

After that open GetClipBoardData.html, it will ask for authentication, just
click on run button.




then try to copy any text and press GetClipBoardData button
you will find your copied text.


Download here full code









How to show place in Google map

How to show place in Google map
-----------------------------------

1) Create a table "latandlon" in Mysql/Oracle/Sqlserver/DB2 in which you feel easy.

CREATE TABLE latandlon (
  id int(11) NOT NULL auto_increment,
  lat decimal(10,6) NOT NULL default '0.000000',
  lon decimal(10,6) NOT NULL default '0.000000',
  address varchar(255) NOT NULL default '',
  PRIMARY KEY  (id)
);


2) feed the listed below data.
----------------------------------------------------------
id,     lat,            lon,            address
----------------------------------------------------------
1    23.402800    78.454100    Madhya Pradesh
2    26.280000    80.210000    Kanpur
3    31.122027    77.111664    Himanchal Pradesh
4    22.533000    88.367000    Kolkata
5    28.350000    77.120000    Delhi
6    17.230000    78.290000    Hyderabad
----------------------------------------------------------





3) put youe google map key in the index.jsp.


 <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*" %>
<%
// How to show place in google map
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
   <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
<script src="http://maps.google.com/maps?file=api&v=2&key=YOURKEYHERE" type="text/javascript">
</script>
<body>
<p><strong>locations in India</strong></p>
<div id="map" style="width: 800px; height: 600px"></div>

<script type="text/javascript">
//<![CDATA[
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(23.402800, 78.454100), 5, G_NORMAL_MAP);
function createMarker(point, number)
{
var marker = new GMarker(point);
var html = number;
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
return marker;
};
<%
    String userName = "root";
    String password = "";
    String url = "jdbc:mysql://localhost:3306/test";
    try{
        String driver = "com.mysql.jdbc.Driver";
        Class.forName(driver).newInstance();
        Connection conn;
        conn = DriverManager.getConnection(url, "root","");
        Statement s = conn.createStatement ();
        s.executeQuery ("SELECT *from latandlon");
        ResultSet rs = s.getResultSet ();
        int count = 0;
        while (rs.next ()) {
            String lat = rs.getString ("lat");
            String lon = rs.getString ("lon");
            String address=rs.getString ("address");
            out.print("var point = new GLatLng("+lat+","+lon+");\n");
            out.print("var marker = createMarker(point, '"+address+"');\n");
            out.print("map.addOverlay(marker);\n");
            out.print("\n");
        }
        rs.close ();
        s.close ();
    }
    catch(Exception ee){
        System.out.println(ee.toString());  
    }
%>
//]]>
</script>
</body>
</html>

4) change the database connection string in the index.jsp page, coz I have used MySql.







Transform XML file in HTML with XSLT in JSP

Transform XML file in HTML with XSLT in JSP

How to transform xml file in html with xslt in J2EE, JSP
----------------------------------------------------------
I have used SAXON XSLT and XQuery Processor library http://saxon.sourceforge.net/
1)saxon9ee.jar 2)saxon9ee-qc.jar 3)saxon9-sql.jar

The Latest version you can download from http://prdownloads.sourceforge.net/saxon/saxon6-5-5.zip
or from here http://sourceforge.net/projects/saxon/

There are 3 xml files for testing purpose
1) result.xml having result information.
2) result_notfound.xml having no any result information.
3) TestSearchResult.xml having partial result information.

you can change xml file to see different html result.

In the xsl file I have used some basic function like count(),position(),and images also showing.

*To open this project use MyEclipse6.0 or later.

Download here xml to html entire code





Add new row dynamically in JTable

This is Java code allow to you add a new row in JTable.
when you press enter then a new row automatically inserted and you can make more entry.



See here full code

Wednesday, June 15, 2011

Delete recent file automatically

Recent files Terminator

Windows Recent document is good for us, by this we can open recent document immediately. but in the case of privacy it is not good. because someone can open/see your Important document.
To prevent this you can clear the recent document list. But what will happen when someone immediately came to near you and try to use your system,in this case you have not sufficient time to clear recent document. There are many software are available that clear recent file but they clear the recent file on system start-up or shut down not immediately! The above problem is really interesting.
okay, so I have created this small and powerful utility.
it will remove the recent file immediately and intervals when you open it.
It will help you to protect to see your important document from Other user.

To run this utility you need to install dot net framework 3.5

Download here

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

Export to excel with preserve starting(Leading) zeros values in ASP Dot Net.

In my office colleague was facing an interesting problem.
Sql sever data was listed below:
-------------------------------------------
ID EmpID EmpName Salary
1 000001 aa 1111111
2 000002 bb 2222222
3 000003 cc 3333333
4 000004 dd 4444444
5 000005 ee 5555555
-----------------------------------------
Column EmpID was varchar type, he was just trying export these data to MS-Excel,
so first show the data by GridView and then export it as a excel file.
But while opening excel file "000001" was showing as "1" and "000002" was showing as "2" and so on. the situation was "00000" were removed as below.
-------------------------------------------
ID EmpID EmpName Salary
1 1 aa 1111111
2 2 bb 2222222
3 3 cc 3333333
4 4 dd 4444444
5 5 ee 5555555
6 6 ff 6666666
----------------------------------------
He just requested me to help and I helped him.I've searched these problem in Microsoft site(MSDN) and found the solution
and implemented it. now he is getting right data in excel.


Download code here

Tuesday, June 14, 2011

Notice Use of undefined constant - assumed in on line error

Notice: Use of undefined constant  - assumed '_' in .....php on line nn

This is the error which many PHP programmer face in coding.
The most important fixes are listed below:
1- you have not declared contant, so declared it
2- use single or double quotes in constant for ex: define('MYCONST', "abc")
3- many  use short open tag "<?" so enable it or user "<?php".





Monday, June 6, 2011

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS,jQuery

Set focus in next control on enter in PHP,ASP.NET,JSP,SERVLETS.


Download latest jQuery and apply listed below code in your web page.


<script language="javascript" src="../js/jquery-1.6.js" type="text/javascript"></script>
<input type="text" name="t1" id="t1" onkeyup="javascript: if(setFocusNext(event)) $('#t2').focus();" />
<br/>
<input type="text" name="t2" id="t2" onkeyup="javascript: if(setFocusNext(event)) $('#t3').focus();" />
<br/>
<input type="text" name="t3" id="t3" />
<script type="text/javascript">
    function setFocusNext(e){
    var cd=0;
    if(window.event) {
        cd = e.keyCode;
    } else if(e.which) {
        cd = e.which;
    }
    if(cd==13) {
        return true;
    } else {
        return false;
    }
}
</script>

Friday, June 3, 2011

Images To Text/Extract text from images (OCR) in dot net

Images To Text / Extract text from images (OCR) in dot net


Here is the application that will takes the directory, where all images
are stored and convert those images to text by one click.

link for that application

Thursday, June 2, 2011

Sending email in PHP from Gmail

Sending email in PHP from Gmail

For sending email in PHP by Gmail id, I have used phpmailer class.
Note that php_openssl must be un-commented in the php.ini file.
In phpMailer directory open "class.phpgmailer.php"  and change the line as listed below:
var $Host        = "ssl://smtp.gmail.com";
var $Port        = 465;


Put listed below code in php file from where you want to send email.
require_once('phpgmailer/class.phpgmailer.php');
$mailToClient=new PHPGMailer();
$mailToClient->IsHTML(true);
$mailToClient->Username='full-gmail-address';//'a@gmail.com';  
$mailToClient->Password='gmail-password-here';//amitabc123  
$mailToClient->From='full-gmail-address';//a@gmail.com';  
$mailToClient->FromName='Amit';
$mailToClient->Subject='YOUR-SUBJECT';//a@gmail.com
$mailToClient->AddAddress('recipient email address here');
$mailToClient->Body='Hey, Here is Amit!';
$mailToClient->Send();

Wednesday, June 1, 2011

Reading XML in jQuery/Generate sitemap in jQuery

Reading XML in jQuery/Generate sitemap in jQuery

Here listed below code is showing that how can you can generate site map with jQuery.
just copy the sites.php file's matter in your site's  sites.php and copy sites.html file's matter
in your  sites.html file.



 sites.php

< ? php
header( 'Content-type: text/xml' );
$xmlData='';
echo '';
$xmlData .= ' < sites >';
$xmlData.='   < site id="0">';
$xmlData.="     < ttitle >Amit's Blog < /ttitle >";
$xmlData.='    < url >http://amitkgaur.blogspot.com/< / url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >Find interesting stuff in Java, PHP and Dot Net.< / brief >';
$xmlData.='       < long >This site is for Humans, smart Primates and Dolphins only (oh and ALIENS).';
$xmlData.='     < /desc >';
$xmlData.='   < / site >';
$xmlData.='   < site id="2" >';
$xmlData.='     < ttitle >Auto Resume Broken File Upload Applet With Progress Bar< /ttitle >';
$xmlData.='    < url >http://amitkgaur.blogspot.com/2010/10/file-upload-applet-with-auto-resume.html< /url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >Upload unlimited GBs file without fear of internet connection break.< / brief >';
$xmlData.='       < long >I have created this Java Auto Resume Broken and Progress Bar File Uploader Applet.< / long >';
$xmlData.='     < / desc >';
$xmlData.='   < / site >';
$xmlData.='   < site id="3" >';
$xmlData.='     < ttitle >Desktop Screen Recorder< / ttitle > ';
$xmlData.='    < url >http://amitkgaur.blogspot.com/2010/09/desktop-screen-recorder.html< /url >';
$xmlData.='     < desc >';
$xmlData.='       < brief >This Screen Recorder will record your screen and generate .MOV file,
I have created it in Java Swing Framework.< / brief >';
$xmlData.='       < long >This Screen Recorder will record your screen and generate .MOV file,
I have created it in Java Swing Framework.
I recommend VLC player to play this file.< / long >';
$xmlData.='     < / desc >';
$xmlData.='   < / site >';
$xmlData.=' < / sites >';
echo $xmlData;
? >



sites.html

   < script type="text/javascript" src="jquery-1.6.js" > < / script >
     < script >
         $(document).ready(function(){
            $.ajax({
                type: "POST",
                url: "sites.php",
                dataType: "xml",
                success: function(xml) {
                    $(xml).find('site').each(function(){
                        var id = $(this).attr('id');
                        var ttitle = $(this).find('ttitle').text();
                        var url = $(this).find('url').text();
                    $('
').html(''+ttitle+'').appendTo('#siteMap');
                        $(this).find('desc').each(function(){
                            var brief = $(this).find('brief').text();
                            var long = $(this).find('long').text();
                            $('
').html(brief).appendTo('#link_'+id);
                            $('
').html(long).appendTo('#link_'+id);
                        });
                    });
                }
            });
        });
    
    <div id="siteMap" >
         Sitemap with jQuery
     </div>