For smart Primates & ROBOTS (oh and ALIENS ).

Blogroll

Saturday, July 19, 2014

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.

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);
% > 
Share:

Friday, July 11, 2014

Add html tag dynamically in html

Add html tag dynamically in html

<script src="jquery-2.1.1.js" language="javascript" type="application/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var ID = 1;
        function addRow() {
            var html =  '<tr>' +
                        '<td>Name: <input type="text" name="aa' + ID + '" /></td>' +
                        '<td>File: <input type="file" name="fileUpload' + ID + '" /></td>' +
                        '<td><input type="button" class="BtnPlus" value="+" /></td>' +
                        '<td><input type="button" class="BtnMinus" value="-" /></td>' +
                        '</tr>'
            $(html).appendTo($("#Table1"))
            ID++;
        };
        $("#Table1").on("click", ".BtnPlus", addRow);
        function deleteRow() {
            if(ID==1) return;
            var par = $(this).parent().parent();
            par.remove();
            ID--;
        };
        $("#Table1").on("click", ".BtnMinus", deleteRow);
    });
</script>
<table id="Table1" cellspacing="3">
    <tr>
        <td>Name: <input type="text" name="aa0"  id="aa0" /></td>
        <td>File: <input type="file" name="fileUpload0"/></td>
        <td><input type="button" class="BtnPlus" value="+" /></td>
        <td><input type="button" class="BtnMinus" value="-" /></td>
    </tr>
</table>
Share:

Display content with delay in jquery

Display content with delay in jquery

Some time you want to show some data with delay, then use the listed below code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Display content with delay</title>
<style>
.my-class {
    display: none;
}
</style>
<script language="javascript" src="jquery-1.10.2.js" type="text/javascript"></script>
</head>
<body>
<div class="my-class">
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
  <p>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</p>
</div>
</body>
<script>
$(document).ready(function() {
$('.my-class').delay(1000).fadeIn(3500);
});
</script>
</html>
Share:

Fieldset in html

Fieldset example in html
----------------------------
Fieldset is very useful to combine the more than one information which you want to show or
feed data entry. actually it will block the more than one columns (all colums will be shown in one
box with header heading).

<fieldset style="text-align:right; width:300px;" accesskey="c">
<legend><b>Address Details</b></legend>
Name <input type="text" size="50" /><br>
Address <input type="text" /><br>
City <input type="text" /><br>
State <input type="text" />
</fieldset>
Share:

Tuesday, July 08, 2014

Sum datagridview cell by button click c#

If you have enter many records in datagridview in c# winform and want to show the sum of any cell values for example: "mark" cell, then you needed to retrieve each datagridview row and add it's value in other variable.... but we want to do this not using iteration.. thwn what we will do?

Use listed below code to achieve target:

---------------------------------------------------------------------------------------------------
string m = "Total Marks =" + dataGridView1.Rows.Cast<DataGridViewRow>().AsEnumerable()                                                    .Sum(x => int.Parse(x.Cells["mark"].Value.ToString())).ToString();
---------------------------------------------------------------------------------------------------


Share:

Sort Datagridview column by button click c#

Sort Datagridview column by button click c#

If you have added the random records in your Datagridview C# winform and want to show records by any column on button click then use this:

-------------------------------------------------------------------------------------
dataGridView1.Sort(dataGridView1.Columns[1], ListSortDirection.Ascending);
-------------------------------------------------------------------------------------
OR
-------------------------------------------------------------------------------------
dataGridView1.Sort(dataGridView1.Columns["mark"], ListSortDirection.Ascending);
-------------------------------------------------------------------------------------

"mark" is the cell name in the datagridview.


Share:

Saturday, July 05, 2014

Image rotate in jQuery

Image rotate in jQuery


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<img style="transform: rotate(285.4deg);" id="myimg"  src="WOW.jpg">
<script type="text/javascript">
    jQuery(function($) {
        $(document).ready(function() {
            window.imagerotate = function () {
                $('#myimg').rotate({
                                angle:0,
                                animateTo:-360,
                                callback: imagerotate,
                                //t: current time,b: beginning value,c: change in value,d: duration
                                easing: function (x,t,b,c,d) {
                                    return c*(t/d)+b+10000;
                                }
                            });
                        };
                        setTimeout('imagerotate()', 1000);
                });
});
</script>
</body></html>          
Share:

Send Files to IP address in C#

If there are you situation you want to send file to IP address,
then use listed below code:

string sourceDir = @"C:\\tt";
string destIP = @"\\10.10.10.10\shared-folder-amit";
string[] sourceFiles = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories);
foreach (string files in sourceFiles) {
  string localFile = files.Replace(sourceDir, "");
  if (!Directory.Exists(Path.GetDirectoryName(destIP + "\\" + localFile)))
    Directory.CreateDirectory(Path.GetDirectoryName(destIP + "\\" + localFile));
  File.Copy(files, destIP + "\\" + localFile, true);
}



Share:

CodeIgniter Undefined property CI_Loader $session codeigniter error

Problem:

If you works in CodeIgniter and play with session then you can get this error message :
Undefined property: CI_Loader::$session

CodeIgniter Undefined property CI_Loader $session codeigniter error

A PHP Error was encountered CodeIgniter
CodeIgniter error

 Severity: Notice
Message: Undefined property: CI_Loader::$session

Solution:

It means that you have not loaded session library in it controller's index or constructor as
$this->load->library('session'); 

Example:

To prevent this error message use listed below code:

public function index() {
        $this->load->library('session');
}
Share:

selected check box record from DataGridView c# winform

Suppose you have a DataGridView with the check box. Data are showing and you want to store only those data that's check boxes is selected, so what you will do? In simple you will use the loop which will retrieve all data from DataGridView from first row to last row and in that loop check the condition is which rows’s check box is selected.

It is a good way but not a smart way, imagine that there are 99999999 rows in the DataGridview and only 100 rows are selected.

Smart way is only create a loop which iterate only 100 times not for 99999999 times.

The Smart way is listed below:
1) Assume that we have the DataGridView with records and also have the check box and its name is "selectMe".

2) use listed below code to retrieve only selected checkboxes.

List<DataGridViewRow> list = dataGridView1.Rows.Cast<DataGridViewRow>().Where(eachrow => Convert.ToBoolean(eachrow.Cells["selectMe"].Value) == true).ToList();
foreach (var row in list) {
    MessageBox.Show(row.Cells["emp_id"].Value.ToString());
}
Share:

Multiple attribute passing in querySelectorAll

Multiple attribute passing in querySelectorAll     Here I am demonstrating code to how to pass multiple attributes in querySelectorAll. <...

Ads Inside Post

Powered by Blogger.

Arsip