Wednesday, December 30, 2009

Post Xml data without form in JSP and receive

How to post xml data in JSP page without form field and get it's data
in the next JSP page.

The first file post-data.jsp is just taking xml data form xml file and
sending xml data as a post to the get-post.jsp page.

Find Full Solution Here:
http://agalaxycode.blogspot.in/2014/07/post-xml-data-without-form-in-jsp-and.html


first file is:
post-data.jsp
--------------
< %@ page import="java.net.*" % >
< %@ page import="java.io.*" % >
< %@ page import="java.util.*" % >
< %@ page import="java.text.*" % >
< %
try
{
URL u;
u = new URL("http://localhost:9292/post/get-post.jsp");
// get the xml data from xml file which you want to post
String inputFileName="C:\\temp1.xml";
FileReader filereader =new FileReader(inputFileName);
BufferedReader bufferedreader=new BufferedReader(filereader);
String initial=bufferedreader.readLine();
String finalData=new String();
while(initial!=null)
{
finalData=finalData+initial;
initial=bufferedreader.readLine();
}
String s=(finalData.toString());
HttpURLConnection uc = (HttpURLConnection)u.openConnection();
uc.setRequestMethod("POST");
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setRequestProperty("Content-Type", "text/xml; charset=\"utf-8\"");
uc.setAllowUserInteraction(false);
DataOutputStream dstream = new DataOutputStream(uc.getOutputStream());
dstream.writeBytes(s);
dstream.close();
InputStream in = uc.getInputStream();
BufferedReader r = new BufferedReader(new InputStreamReader(in));
StringBuffer buf = new StringBuffer();
String line;
while ((line = r.readLine())!=null) {
buf.append(line);
}
in.close();
out.println(buf.toString());
}
catch (IOException e)
{
out.println(e.toString());
}
% >


Second file is:
get-post.jsp
-----------------

< %@ page import="java.util.*" % >
< %
String postedData = request.getReader().readLine();
///// perform here your operation for postedData
out.println("Posted Data is ");
out.println(postedData);
% >

Tuesday, December 29, 2009

Post Xml data without form in PHP and receive

How to post Xml data without form in PHP and receive
=====================================================
If it is not working in localhost/localsystem, try to run it in from live server.


here is the first file which will send xml data

vp-post4.php
-------------
< ? php
#get the xml data from xml file which you want to post
$xml = file_get_contents("temp1.xml");
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml",
'content' => $xml
)));
// put here host name with page name.
// if it is not working in local try to run it in live server.
$file = file_get_contents("http://localhost:90/post/vp-postget4.php", false, $context);
echo $file;
?>


here is the second file which will receive xml data

vp-postget4.php
-------------------

< ? php
$xml = file_get_contents("php://input");
// perform here your operation for received xml data
/////// .....
/////// .....
echo "received data is : ".$xml;
?>

Wednesday, December 16, 2009

Get current logged user user_id in Social Engine 4

How to get current logged user user_id in Social Engine 4

As you know that Social engine used Zend framework.
In any page if you need current logged in user's user_id then you can find it via this
one piece of line code:

$currentUserID=Engine_Api::_()->user()->getViewer()->getIdentity();
echo $currentUserID;


now current logged in user's id stored in the variable $currentUserID,
you can use it in your code as you want.

Info tab is not working in Social Engine 4

Member Info tab is not working in Social Engine 4


I was working fix bugs in social engine 4. There were lot of bugs, but the one bug was very strange.  When any user logon and see own profile by clicking on “My Profile” link.
A sub menu tab is show with “Updated”, “Notes”, “My Contacts Groups” etc.
The sub menu tab “Updated”, “Notes”, “My Contacts Groups” are working but after the rest all sub tabs for ex: “Info”, “Contacts”, “Albums” and in “More+” dropdown tabs links were  not working.  The same problem was occurring when any logged in user see his/her friend’s or other user’s profile, that’s information were not coming.


Info tab is not working in Social Engine 4
Info tab is not working in Social Engine 4




















I have solved it. If you are facing the same problem then make the listed below changes:

1) Open the file   container-tabs's Controller.php file

2) Goto line number 56 and search the listed below code:
$childrenContent .= $child->render() . PHP_EOL;  

3) Make it comment:
//$childrenContent .= $child->render() . PHP_EOL;

4) and paste listed below code:

 if($child->getIdentity()=="945") {
            $cntDivStart=count(explode("<div", $child->render()))-1;
            $cntDivEnd=count(explode("</div", $child->render()))-1;
            if($cntDivEnd<$cntDivStart) {
                        $childrenContent .= $child->render() ."</div>". PHP_EOL;
            } else  {
                        $childrenContent .= $child->render() . PHP_EOL; 
            }
} else {
            $childrenContent .= $child->render() . PHP_EOL;
}

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());
}
}
}