December 31, 2009
This is one of the knows patterns in the web devs. The idea would be having two – or possibly more – frames and making one the front one for interaction while would be HIDDEN.
Why Hidden?
The visible frame would pass make a request to the hidden frame to make the server side interaction behalf of it. Doing so would make the visible frame to remain loaded. The hidden would play the rest of the game by consulting the server and grabbing all the required data. Of course, how do they talk? well, Mr. Javascript will be the ‘man in the middle’ – don’t wanna mention the security flaw known by this name
Let’s see a quick example: the example will show how to interact with the server side script without page reload. For demo purpose, A page will accept first name and last name and will display the concatenated full name. Though the logic done is is too easy to accomplish, one has to bear in mind that any complex logic can be done in the same way.
First create a simple index file containing the frames
<html>
<head><title>Lab01</title>
<frameset rows="100%, 0" style="border: 0px">
<frame name="visibleframe" src="enterName.html" noresize="noresize"></frame>
<frame name="hiddenframe" src="about:blank" noresize="noresize"></frame>
</frameset>
</head>
</html>
Making the frameset row 100% will assure the full visibility.
Then have the page for first and last name.
enterName.html.
<script>
//get full name by delegating the task to the php
function getFullName(){
var firstName = document.getElementById("txtFirstName").value;
var lastName = document.getElementById("txtLastName").value;
top.frames["hiddenframe"].location = "concateName.php?firstName="+firstName+"&lastName="+lastName;
}
//display it on the front page
function showFullName(fullName){
showdiv = document.getElementById("fullName");
showdiv.innerHTML = fullName;
}
</script>
Your First Name <input type="text" id = "txtFirstName" name="txtFirstName" /> <br>
YOur Last Name<input type="text" id="txtLastName" name="txtLastName" /> <br>
<input type="submit" name="subGetFullName" value = "concate" onClick="getFullName();" /> <br>
<textArea id="fullName" name="fullName"></textArea>
This file contains two javascripts: one for sending the form values to the hidden frame and the other to accept and display the result from the hidden frame.
Since the hidden frame had no source initially, the getFullName() function would be responsible for assigning the file to it.
Now lets build the server side script which will combine and return the full name
concateName.php
<!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><title></title>
<script>
window.onload = function(){
var fullNameDiv = document.getElementById("fullName");
top.frames["visibleframe"].showFullName(fullNameDiv.innerHTML);
};
</script>
<?php
$firstName = $_GET['firstName'];
$lastName = $_GET['lastName'];
$fullName = $firstName . $lastName;
?>
</head>
<body><div id="fullName"><?php echo "FULL name is " . $fullName ?>
</div></body>
</html>
Now we are done. 
The concateName.php would get the parameters from the enterName.html through hiddenframe. Once it access the values, it will concatenate them and will deploy the result in the “fullName” div.
The defined window.onload would wait until things are in place and it will fire the result back to the “visibleframe” through javascript.
Now – the user has no what is going on behind he scene – as she will not see the page being reloaded on refreshed.
reference: Professional Ajax 2nd edition Wrox
Leave a Comment » |
PHP, jQuery/JavaScript/CSS | Tagged: hidden frame pattern, pattern, hidden pattern, javascript frame, frameset frame, frame javascript, php frameset, php javascript, javascript, frameset ajax, php ajax, javascrpt ajax, ajax frameset, ajax frame, php with frameset ajax, hidden and visible framesets, interacting with server using frameset, avoiding reloading page |
Permalink
Posted by gullele
December 30, 2009
The idea behind using SSH (secure shell) falls when one is interested in sending files over the network in secure way. There are existing methods which will accomplish the task, but SSH is a cool one when one wants real security.
Here is the step to send files securely from your machine to the other.
1. install ssh client and ssh server using
sudo apt-get install openssh-client openssh-server
2. log into the server using the command
ssh username@server
where username is the user at the server. This can be checked on local machine as ssh user@localhost
3. Now we can share files using the tool scp
to upload file use:
scp path/to/file/to/upload user@server:/path/to/host/directory
Say, to upload the file test.txt from local machine to server named someserver.com into directory /home/remote, then
scp /home/user/test.txt user@someserver.com:/home/remote
And to download file from the same server to local machine
scp user@someserver.com:/home/remote/test.txt /home/user/downloads
This one required logging every time with subsequent request of password. To setup a secure file transfer without password the way to go would be using public private combination between server and client.
Generating and using public private key
1. Creating Public Private key can be done using:
ssh-keygen -t dsa – or if you want to make rsa: ssh-keygen -t rsa
2. it will prompt you to where to put the file and the passkey for the files. take default file path. This would allow the creation of id_dsa (private key) and id_dsa.pub (public key) into the ssh directory. -> The directory would be into /home/user/.ssh/. The private key would retain with the generating server while the public key would be uploaded to the server where you would create the connection.
3. Make sure the following are available and not commented in /etc/ssh/ssh_config
IdentityFile ~/.ssh/identity
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_dsa
4. Make sure you have id_dsa, id_dsa.pub or rsa versions on .ssh folder
5. Copy the public key to the remote server using
scp /path/to/publickey user@server:/home/user/.ssh/ – where user is the authenticated user on the remote server
6. You will be asked for one last time your password for copying the file.
7. The file will now be added to the remote server’s authorized_keys. This will give you an access from your machine to the remote server without password – unless you want it to.
reference:
http://www.techotopia.com/index.php/Configuring_Ubuntu_Linux_Remote_Access_using_SSH
http://outhereinthefield.wordpress.com/2007/10/31/passwordless-scp-authentication-for-unattendedbatch-process/
http://www.debuntu.org/ssh-key-based-authentication
Leave a Comment » |
Uncategorized | Tagged: Ubuntu, ssh, file transfer, scp, sshclient, sshserver, client, server, secure file, security, public private, key |
Permalink
Posted by gullele
November 20, 2009
OK, we can use INSERT INTO statement to insert fresh data to mysql. But how about if the need lies on reading data from another table?
Here is how we do it in mysql.
Let us create the tables for illustration:
Log into your mysql and create the following queries
Creating database
CREATE database testdb;
USE testdb;
Creating tables
CREATE TABLE testtbl1 (id int(10) auto_increment, fname varchar(20), lname(20), primary key(id));
CREATE TABLE testtbl2 (id int(10) auto_increment, firstname varchar(20), lastname(20), age int, primary key(id));
Lets add some data to table 2 now
INSERT INTO testtbl2 (firstname, lastname, age)
VALUES
(‘ftest1′, ‘ftest1′, 35),
(‘ftest2, ‘ftest2′, 21),
(‘ftest3, ‘ftest3′, 25),
(‘ftest4′, ‘ftest4′, 38)
Now lets add data to the first table filtering persons with age less than 30
INSERT INTO testtbl1 (fname, lname) SELECT firstname, lastname FROM testtbl2 WHERE age <= 30;
Leave a Comment » |
MySQL | Tagged: from table to table mysql, insert into, MySQL, mysql data insert from table, populating table by reading from table, read from table and store to table in mysql, store, table |
Permalink
Posted by gullele
November 14, 2009
Yup, just to share – as usual.
While working on one of my projects I run this error. Here is the snippet where the error occurs:
....
$carPrice = $this->getCarPrice(); // this would return object of CarPrice
if (empty($carPrice->getCarPriceId()))
{.....
Where $carPrice is an object to be returned after passing an array of data ($new_price) to the controller.
And on the next line, I was trying to if priceId of the car is not empty.
The problem is caused on the second operand of the if statement (empty($carPrice->getCarPriceId()) -
Here is how I get fool around..
...
$car_price_id = $carPrice->getCarPriceId();
if (empty($car_price_id))
{
...
It happens that function empty() [and even isset() ] do expect a variable to be checked otherwise, parse error will happen.
Leave a Comment » |
PHP | Tagged: empty, isset, method return value in write context, php error, php return method error |
Permalink
Posted by gullele
September 10, 2009
I just wanted to add my existing Java project to the current java web project and here is the simple step actually [of course from Eclipse
]
1. Right click on the web project and select Properties
2. Select J2EE Module Dependencies
3. Here either you can select the project which resides in the eclipse workspace or you can import additional external jars.
4. Apply OK
5. Right click web project and select Build Path -> configure
6. On the projects tab, select the project tab
7. Click Add and select the project that you would like to add
8. OK.
You are done! It is advisable if you clean your project and build a new one
To to do this:
Go to project -> clean and select your project
Select start a build immediately
Select build only the selected projects
After this reboot your Application Server – and enjoy with your imported project.
Leave a Comment » |
Java Web | Tagged: Add Java Project to java web application, adding existing java applicaition in eclipse, Dynamic web application, Eclipse, tomcat |
Permalink
Posted by gullele
May 18, 2009
Say the table is created like this,
mysql> CREATE TABLE customer (id int, fname varchar(20));
The above table would be created without having an index. If there is a need to make id primary key, then
mysql> ALTER TABLE customer ADD PRIMARY KEY (id);
Then adding auto_increment would be as:
mysql> ALTER TABLE customer CHANGE id id int NOT NULL AUTO_INCREMENT;
Trying to assign auto_increment before making it a primary key – if it is not already done during creation, might produce an error. Actually trying to drop the primary key before neutralizing the auto_increment would also might create an error.
The following query would take out the auto_increment part from the table
ALTER TABLE customer CHANGE id id int not null;
And, of course, after this it is possible to drop primary key.
Leave a Comment » |
MySQL | Tagged: adding auto_increment, dropping auto_increment, index, primary key |
Permalink
Posted by gullele
May 8, 2009
Changing table or colum in SQL Server is as follows,
To change the name of the table:
sp_RENAME ‘tbloldname’, ‘tblnewname’;
To chagne the name of the column:
sp_RENAME ‘tbl.columnoldname’,'columnnewname’,'COLUMN’;
** You might face a problem on changing names of enforced (integrity) columns.
Leave a Comment » |
MS SQL Server |
Permalink
Posted by gullele