Sunday, November 22, 2009

Java file upload applet.

I have created a Two java file upload applet, in one applet just select one directory and all the files in that directory will be uploaded in the server.


And in the other Applet you can upload large file size (GBs) to the server.


How to connect Sql Server 2005 in Java

import java.sql.*;
///////////////////////////////////////////////////////////////////////////
//1) download sel server 2005 driver from :
//http://msdn.microsoft.com/en-us/data/aa937724.aspx
//OR
//http://www.microsoft.com/downloads/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&displaylang=en
//2) set sqljdbc4.jar in your class path.
//3) and run the code.
// By: Amit

//////////////////////////////////////////////////////////////////////////

public class SqlSvrConn
{
public static void main(String[] srg)
{
String driverName= "com.microsoft.sqlserver.jdbc.SQLServerDriver";
//String dbURL = "jdbc:sqlserver://PUT-SQLSERVER-IP-HERE:1433;DatabaseName=PUTDATABASENAMEHERE";
String dbURL = "jdbc:sqlserver://230.100.100.100:1433;DatabaseName=TestDB";
String userName="myusername";
String userPwd="mypassword";
Connection dbConn;
try
{
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL,userName,userPwd);
System.out.println("Connection Successful!");
Statement sta = dbConn.createStatement();
ResultSet res = sta.executeQuery("SELECT TOP 10 * FROM emp");
System.out.println("Customers");
while (res.next()) {
String firstName = res.getString("nName");
String emailName = res.getString("Emailid");
System.out.println(" "+firstName+" "+emailName);
}
dbConn.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Wednesday, November 11, 2009

get name of module, controller and method/action in Zend Framework

// How to get name of module, controller and method/action in Zend Framework.


<?php
    // How to get name of module, controller and method/action in Zend Framework.
    $front1 = Zend_Controller_Front::
getInstance();
    $module1 = $front1->getRequest()->getModuleName();
    $controller1 = $front1->getRequest()->getControllerName();
    $action1 = $front1->getRequest()->getActionName();
    echo "<br/><br/>".$module1;
    echo "<br/><br/>".$controller1;
    echo "<br/><br/>".$action1;
?>

Friday, October 23, 2009

Password secure MD5 in JSP

Password secure as MD5 in JSP



<%@page import="java.security.MessageDigest"%>

<%!
public String inc(String passwd) {
    StringBuffer sb = new StringBuffer();
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.reset();
        md.update(passwd.getBytes());
        byte[] digest = md.digest();
        String hex;
        for (int i=0;i<digest.length;i++){
            hex =  Integer.toHexString(0xFF & digest[i]);
            if(hex.length() == 1){hex = "0" + hex;}
            sb.append(hex);
        }
    } catch(Exception ee) {
               
    }
    return sb.toString();
}
%>


<%
String passwd = "superadmin",inc_pass="";
inc_pass=inc(passwd);
out.print(inc_pass);
%>

Saturday, October 17, 2009

Extended Find and Replace

Extended Find And Replace Utility

This is Extended Find And Replace Utility. By This You Do Multiple(5 Times) Find And Replace Operations in Director and Sub-directory.
It is Also Create BackUp Of Old Files With Current Date.So You can Use That For Further Use. No Worries, It Will Not Stop When it Find The Hidden and ReadOnly Files It Will Replace Those Too.




















To run this utility you ned to install dot net run-time 4.0 from Microsoft site.
Download this utility here





Thursday, September 3, 2009

Simple Html Editor

Simple HTML Editor

I have faced a new problem. client want WYSIWYG editor. there are lot of free HTML editor
available and I can use those very easily, but he don't want those , he want custom simple
HTML editor. so I have create the simple HTML editor. the entire code is listed below:


1) download latest jquery from it's site.

2) create a div

<div contenteditable="true" style="width:600px; height:150px; overflow:scroll; background-color:#CCC" id='my_text'></div>

3) create a textarea
<textarea name="my_text1" id="my_text1" style="display:none;"></textarea>

4) create a submit button.

5) and on click on submit button use this javascript code:
   var my_text=jQuery.trim($("#my_text").html());
   $("#my_text1").val(my_text);

6) and finally submit the form.

in server side code , I have used JSP here:

7) String my_text=request.getParameter("my_text").trim();


Thursday, August 6, 2009

Csv to Html generator

CSV to HTML Generator
==================================
The Csv to Html generator software is a robust software,that can generate html file(s) for each record
which are existing in the csv file. it take only three input A) CSV file B) Html template file
3) Destination directory.

The csv file must be comma separated.
Feature: You can double quotes in the records and in that record you can use comma.

Suppose you have listed below columns 15 in your csv file having many records

sku,standard-product-id,product-id-type,title,manufacturer,mfr-part-number,description,product_type,item-type,search-terms1,search-terms2,search-terms3,search-terms4,search-terms5,main-image-url


and you want to generate individually htnl file with predefined template for the listed below columns
for ex:
sku,product-id-type,manufacturer,description,search-terms2

0 for sku,
2 for product-id-type,
4 for manufacturer
6 for description
9 for search-terms1


then just create a listed below HTML template format file:
<html>
<body>
    Sku of item: [0], <br/>
    Product type  ID: [2], <br/>
    Manufacturer of item: [4] <br/>
    Description:  [6] <br/>
    Search terms 1: [9] <br/>
</body
</html>

Download Here

You need to install Dot Net Framework 4.0 distribution before  run to this Application.


Wednesday, July 8, 2009

Latest Posts

View here my latest posts.

Want to look my latest Posts? just Click here

Wednesday, June 24, 2009

Solid border of table

Solid border of table.


<!DOCTYPE html>
<html>
<head>
<style>
table
{
border-collapse:collapse;
}
table, td, th
{
border:2px solid red;
}
</style>
</head>

<body>
<table>
<tr>
<th>Test1</th>
<th>Test2</th>
</tr>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
</html>

Wednesday, May 13, 2009

JQuery Mobile alert box open after completion of task

JQuery Mobile alert box open after completion of some task


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html class="ui-mobile">
<head>
<title>Products</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
<link type="text/css" href="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.css" rel="stylesheet" />
<link type="text/css" href="http://dev.jtsage.com/jQM-DateBox/css/demos.css" rel="stylesheet" />
<script type="text/javascript" src="http://dev.jtsage.com/cdn/simpledialog/latest/jquery.mobile.simpledialog.min.js"></script>
<script type="text/javascript" src="http://dev.jtsage.com/gpretty/prettify.js"></script>
<link type="text/css" href="http://dev.jtsage.com/gpretty/prettify.css" rel="stylesheet" />
</head>
<body class="ui-mobile-viewport">
<div data-role="page" data-theme="b" data-content-theme="d">
  <div data-role="header" data-position="inline" data-theme="b">
    <h1>Products Listing </h1>
    <a href="#" id="addToCartButton" onclick="addToCart();" data-role="button" data-icon="myapp-shopping" data-theme="c">Add to Cart</a>
</div>
    <div data-role="content">
        Open jQuery Mobile alert box after completion of some task.
    </div>
</div>
<script>
function openDialog(msg) {
    $(document).delegate('#
addToCartButton', 'click', function() {
    $(this).simpledialog({
        'mode' : 'bool',
        'prompt' : msg+"<br/><br/><br/><br/>",
        'useModal': true,
        'buttons' : {  'OK': {  click: function () {   }  } }
                    })
            });
}
function addToCart() {
    // task goes here.....
    var msg="Product added in you cart";
    openDialog(msg);
}
/*$(document).delegate('#addToCartButton', 'click', function() {
    var msg=addToCart();
    $(this).simpledialog({
    'mode' : 'bool',
    'prompt' : msg,
    'useModal': true,
    'buttons' : {
      'OK': {
        click: function () {
           
          //$('#dialogoutput').text('OK');
        }
      }
    }
  })
});*/
</script>
</body>
</html>










Wednesday, May 6, 2009

Read yahoo groups rss by curl and SimpleXmlElement in PHP

..< ?php
// Read yahoo groups rss by curl and SimpleXmlElement
// by Amit gaur  $url = "http://rss.groups.yahoo.com/group/tm_informatikleri/rss"; $req = curl_init(); curl_setopt($req, CURLOPT_URL, $url);
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
$xml = curl_exec($req);
curl_close($req);
$doc = new SimpleXmlElement($xml, LIBXML_NOCDATA);
if(isset($doc->channel))
{
showRSS($doc);
}
function showRSS($xml)
{
echo "".$xml->channel->title."
";
$cnt = count($xml->channel->item);
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$title = $xml->channel->item[$i]->title;
$desc = $xml->channel->item[$i]->description;
$pubDate=$xml->channel->item[$i]->pubDate;
echo ''.$title.'
'.$pubDate.'
'.$desc. ' '. $guid. '

';
}
}
?>

How to send email from Gmail in Java.

import java.io.*;
import java.net.InetAddress;
import java.util.Properties;
import java.util.Date;
import javax.mail.*;
import javax.mail.internet.*;

// Created by Amit Gaur May-4-2009

// How to send email from Gmail in Java

public class GMail
{
public static void main(String ss[])
{
String host = "smtp.gmail.com";
String username = "a";// Put here only Gmail username not full email id
String password = "amitamit";// Put here Gmail password
int i;
i=1;
try
{
Properties props = new Properties();
props.put("mail.smtps.auth", "true");
//props.put("mail.from", "a@gmail.com");
props.put("mail.from",""); // put here from full gmail email id
Session session = Session.getInstance(props, null);
Transport t = session.getTransport("smtps");
t.connect(host, username, password);
MimeMessage msg = new MimeMessage(session);
msg.setFrom();
//msg.setRecipients(Message.RecipientType.TO, "a@gmail.com");
msg.setRecipients(Message.RecipientType.TO, ""); // put here receiver mail id

msg.setSubject("hello amit"+i);
msg.setSentDate(new Date());
msg.setText("Hello, Hi!"+i);
t.sendMessage(msg, msg.getAllRecipients());

}
catch(Exception ee)
{
System.out.println(ee.toString());
}
}
}

Tuesday, October 14, 2008

How to use getParameter on jsp page in liferayportlet

How to use getParameter on jsp page in liferayportlet

First you need to import this liferayportlet package in your JSP page:

<%@ page import="com.liferay.portal.util.PortalUtil" %>

HttpServletRequest myReq = PortalUtil.
getOriginalServletRequest(PortalUtil.getHttpServletRequest(renderRequest));
String myid = myReq.getParameter("myid")
;
out.println("myid="+myid);

Thursday, September 18, 2008

Create new HttpServletRequest object in Servlet

Create new HttpServletRequest object in Servlet

Sometimes you not need to use default object of HttpServletRequest in Servlet, you need to create new object of HttpServletRequest, in this situation you can use listed below code to create new object of HttpServletRequest. in this code just use default object " request" of HttpServletRequest in "doPost" or "doGet" method.



public void doPost(HttpServletRequest request, HttpServletResponse res)
        throws IOException, ServletException {

HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public void doGet(HttpServletRequest request, HttpServletResponse res)
        throws IOException, ServletException {

HttpServletRequest hsr = (HttpServletRequest) request;
// now use hsr

}

Wednesday, September 10, 2008

Download image without cURL and with cURL

Download image without cURL and with cURL

<?php
// without cURL
$downloadImageUrl="http://fc04.deviantart.net/fs26/f/2008/072/b/1/Frozen_Galaxy_by_Vpr87.jpg";
////// Using without CURL
$img = file_get_contents($downloadImageUrl);
$file1 = dirname(__file__).'/aaa.jpg';
file_put_contents($file1, $img);



////// // with cURL
$fileName=$downloadImageUrl;
$header = array(
            "Accept-Encoding: gzip,deflate",
            "Accept-Charset: utf-8;q=0.7,*;q=0.7",
            "Connection: close"
        );
$useragent = 'Amit Kumar Gaur a@gmail.com  http://amitkgaur.blogspot.com';
$file2 = dirname(__file__).'/bbb.jpg';
$curlObj=curl_init();
curl_setopt($curlObj, CURLOPT_HTTPHEADER, $header);
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlObj, CURLOPT_HEADER, false);
curl_setopt($curlObj, CURLOPT_USERAGENT, $useragent);
curl_setopt($curlObj, CURLOPT_CONNECTTIMEOUT, 999);
curl_setopt($curlObj, CURLOPT_TIMEOUT, 9999);
curl_setopt($curlObj, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curlObj, CURLOPT_URL, $downloadImageUrl);
$response = curl_exec($curlObj);
$return = false;
if(!curl_errno($curlObj)) {
    file_put_contents($file2, $response);
}