<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6010256189300350666</atom:id><lastBuildDate>Thu, 24 Oct 2024 20:53:47 +0000</lastBuildDate><category>jquery</category><category>PHP</category><category>JavaScript</category><category>Java</category><category>examples</category><category>Web 2.0</category><category>AJAX</category><category>Database</category><category>Hibernate</category><category>SOAP</category><category>exception</category><category>GWT</category><category>JMesa</category><category>Privacy Policy</category><category>Random</category><category>security</category><category>software</category><category>struts</category><category>tomcat</category><title>Tech Blog</title><description>Java, JSP, JSF, Struts, Hibernate and Ajax from an everyday life. Nothing serious just some thoughts.</description><link>http://ldeveloper.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-5562541455900355500</guid><pubDate>Fri, 09 Sep 2011 14:03:00 +0000</pubDate><atom:updated>2011-09-09T07:03:50.909-07:00</atom:updated><title>More PHP in this blog lately</title><description>Recently I work too much with PHP so naturally this blog will go in this direction. I’m trying to be short and at the point, with small but useful snippets of code. I hope that they will help you in some way.&lt;br /&gt;
I can’t write long and meaningless chunks of text and when I read developers books I tend to read only the code. In very rare occasions I read some other explanations - they are good when you talk about methodology or algorithm but examples are best when you talk about basics. Actually, this is just an excuse. The main reasons for more code than text in this blog is that I can’t write text.</description><link>http://ldeveloper.blogspot.com/2011/09/more-php-in-this-blog-lately.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-6782047144282816662</guid><pubDate>Fri, 09 Sep 2011 13:49:00 +0000</pubDate><atom:updated>2011-09-09T07:04:35.779-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">examples</category><category domain="http://www.blogger.com/atom/ns#">exception</category><category domain="http://www.blogger.com/atom/ns#">PHP</category><title>How to make tar and tar.gz archives with PHP</title><description>This question is somewhat painful for me. Maybe I am too stupid. Anyway, if you want to make tar archive without using exec, for example on Windows machine without tar tool or any other stupid reason, here is how to do it with PHP. Its actually very easy if you know how to do it.&lt;br /&gt;
&lt;br /&gt;
For example lets have a directory called dir and we want to make an archive with its content. The solution for our problem is Phar.&lt;br /&gt;
&lt;br /&gt;
Here is the code that do the job:&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;lt;&lt;/font&gt;?&lt;font color=&quot;#2040a0&quot;&gt;php&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// we want to archive all files from this directory&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;dir&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;dir/&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// the name of our new tar&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;phar&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;strong&gt;new&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;Phar&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;ourarchive.phar.tar&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// build from our dir&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;phar&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;-&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;buildFromDirectory&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;dir&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// we are using gzip comppression&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;phar&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;-&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;compress&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;Phar&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;:&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;:&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;GZ&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

?&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;
&lt;/pre&gt;Look carefully at the name of our archive - the parameter that we give when we create Phar object. It ends with phar.tar. If you use only .tar it will return error:&lt;br /&gt;
&lt;div style=&quot;color: #38761d;&quot;&gt;Fatal error: Uncaught exception &#39;UnexpectedValueException&#39; with message &#39;Cannot create phar &#39;ourarchive.tar&#39;, file extension (or combination) not recognised&lt;/div&gt;This is not fun if you are trying to create tar and you receive this message. So using file name that ends with phar.tar will fix the problem.&lt;br /&gt;
&lt;br /&gt;
If you receive error:&lt;br /&gt;
Fatal error: Uncaught exception &#39;BadMethodCallException&#39; with message &#39;Unable to add newly converted phar &quot;/www/pro/ourarchive.phar.tar&quot; to the list of phars, a phar with that name already exists&#39;&lt;br /&gt;
most likely your tar file already exist.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://ldeveloper.blogspot.com/2011/09/how-to-make-zip-archives-with-php-part.html&quot;&gt;Learn here how to make Zip archives with PHP&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2011/09/how-to-make-tar-and-targz-archives-with.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-8881705050330429777</guid><pubDate>Fri, 09 Sep 2011 12:49:00 +0000</pubDate><atom:updated>2011-09-09T05:52:24.686-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">examples</category><category domain="http://www.blogger.com/atom/ns#">PHP</category><title>How to make Zip archives with PHP - part 1</title><description>Actually working with zip archives isn’t that obvious that it looks from the documentation. But if you want an adventure try to make tar or tar.gz. Actually in one of my next posts I will describe the procedure. Now, we are talking about zip here.&lt;br /&gt;
&lt;br /&gt;
Example: Create archive and add file to it&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;lt;&lt;/font&gt;?&lt;font color=&quot;#2040a0&quot;&gt;php&lt;/font&gt;
 &lt;font color=&quot;#444444&quot;&gt;// the file that we want to compress&lt;/font&gt;
 $&lt;font color=&quot;#2040a0&quot;&gt;file&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;path/filetocompress.txt&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 
 &lt;font color=&quot;#444444&quot;&gt;// how we want to name the file in the archive&lt;/font&gt;
 $&lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;filename.txt&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 
 &lt;font color=&quot;#444444&quot;&gt;// we need to create new object&lt;/font&gt;
 $&lt;font color=&quot;#2040a0&quot;&gt;zip&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;strong&gt;new&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;ZipArchive&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 
 &lt;font color=&quot;#444444&quot;&gt;// we are using ZipArchive::open with flag CREATE to make new zip archive&lt;/font&gt;
 &lt;strong&gt;if&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;zip&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;-&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;open&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;ournew.zip&amp;quot;&lt;/font&gt;, &lt;font color=&quot;#2040a0&quot;&gt;ZipArchive&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;:&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;:&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;CREATE&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;TRUE&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

  
  &lt;font color=&quot;#444444&quot;&gt;// here the first parameter is the file on our system&lt;/font&gt;
  &lt;font color=&quot;#444444&quot;&gt;// the second is the name to be used for this file in our new zip &lt;/font&gt;
     $&lt;font color=&quot;#2040a0&quot;&gt;zip&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;-&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;addFile&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;file&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

     
     &lt;font color=&quot;#444444&quot;&gt;// close is used for both close and save&lt;/font&gt;
     $&lt;font color=&quot;#2040a0&quot;&gt;zip&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;-&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;close&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt; &lt;strong&gt;else&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

     &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &#39;&lt;font color=&quot;#2040a0&quot;&gt;Error&lt;/font&gt;&#39;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
?&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;

&lt;/pre&gt;</description><link>http://ldeveloper.blogspot.com/2011/09/how-to-make-zip-archives-with-php-part.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-2124982811703117846</guid><pubDate>Fri, 09 Sep 2011 12:17:00 +0000</pubDate><atom:updated>2011-09-09T05:17:16.181-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">examples</category><category domain="http://www.blogger.com/atom/ns#">PHP</category><title>Fast PHP example - FTP file upload</title><description>Here is one fast and simple example on how to do FTP file uploads with PHP.&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;lt;&lt;/font&gt;?&lt;font color=&quot;#2040a0&quot;&gt;php&lt;/font&gt;

$&lt;font color=&quot;#2040a0&quot;&gt;ftp_server&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;ftp.server.url&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

$&lt;font color=&quot;#2040a0&quot;&gt;ftp_user&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;user&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;ftp_password&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;password&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

$&lt;font color=&quot;#2040a0&quot;&gt;file_to_upload&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;localfile.txt&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;remote_location&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;/location/file.txt&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// set up connection or exit with message&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;flink&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;ftp_connect&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;ftp_server&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;or&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;exit&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;Can&#39;t connect to ftp server: $ftp_server&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// login or at least try  &lt;/font&gt;
&lt;strong&gt;if&lt;/strong&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;ftp_login&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;flink&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;ftp_user&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;ftp_password&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

 
 &lt;font color=&quot;#444444&quot;&gt;// if login successful use ftp_put to upload the file&lt;/font&gt;
 &lt;font color=&quot;#444444&quot;&gt;// if you upload binary files use mode FTP_BINARY&lt;/font&gt;
 &lt;strong&gt;if&lt;/strong&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;ftp_put&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;flink&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;remote_location&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;file_to_upload&lt;/font&gt;, &lt;font color=&quot;#2040a0&quot;&gt;FTP_ASCII&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

  &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;Success! File is uploaded!&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt; &lt;strong&gt;else&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;Can&#39;t upload file&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt; &lt;strong&gt;else&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;Can&#39;t login with this user &amp;amp; password&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#444444&quot;&gt;// close the connection&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;ftp_close&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;flink&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

?&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;
&lt;/pre&gt;You can get more information at &lt;a href=&quot;http://www.php.net/manual/en/ref.ftp.php&quot;&gt;http://www.php.net/manual/en/ref.ftp.php&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2011/09/fast-php-example-ftp-file-upload.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-8692675904301321458</guid><pubDate>Fri, 19 Aug 2011 08:25:00 +0000</pubDate><atom:updated>2011-08-19T02:19:27.082-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PHP</category><title>PHP : Handling file uploads - easy tutorial with example</title><description>Handling file uploads with PHP is very easy task and here you will learn how to do it. And because I believe that people learn best with examples lets start with this.&lt;br /&gt;
Now lets upload one file to some user directory on a server. Lets create file upload_form.php on our server. It will contain mainly html code:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;upload_form.php&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;form&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;enctype=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;multipart/form-data&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;action=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;upload.php&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;method=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;POST&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    File: &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;input&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;ourfile&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;type=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;file&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;type=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;submit&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Upload&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/form&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;br /&gt;
Its very simple file with only one form. Don’t forget to add enctype=&quot;multipart/form-data&quot; to your form when its used for file uploads. In this form we have to fields - the first is our file and the second is the submit button.&lt;br /&gt;
Now we need another file upload.php. Here is its content&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;upload.php&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;4444FF&quot;&gt;&amp;lt;&lt;/font&gt;?&lt;font color=&quot;#2040a0&quot;&gt;php&lt;/font&gt;
$&lt;font color=&quot;#2040a0&quot;&gt;dir&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &#39;/&lt;font color=&quot;#2040a0&quot;&gt;var&lt;/font&gt;/&lt;font color=&quot;#2040a0&quot;&gt;www&lt;/font&gt;/&lt;font color=&quot;#2040a0&quot;&gt;files&lt;/font&gt;/&#39;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

$&lt;font color=&quot;#2040a0&quot;&gt;destinationfile&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $&lt;font color=&quot;#2040a0&quot;&gt;dir&lt;/font&gt; . &lt;font color=&quot;#2040a0&quot;&gt;basename&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;_FILES&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;[&lt;/font&gt;&#39;&lt;font color=&quot;#2040a0&quot;&gt;ourfile&lt;/font&gt;&#39;&lt;font color=&quot;4444FF&quot;&gt;]&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;[&lt;/font&gt;&#39;&lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt;&#39;&lt;font color=&quot;4444FF&quot;&gt;]&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;strong&gt;if&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;move_uploaded_file&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;(&lt;/font&gt;$&lt;font color=&quot;#2040a0&quot;&gt;_FILES&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;[&lt;/font&gt;&#39;&lt;font color=&quot;#2040a0&quot;&gt;ourfile&lt;/font&gt;&#39;&lt;font color=&quot;4444FF&quot;&gt;]&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;[&lt;/font&gt;&#39;&lt;font color=&quot;#2040a0&quot;&gt;tmp_name&lt;/font&gt;&#39;&lt;font color=&quot;4444FF&quot;&gt;]&lt;/font&gt;, $&lt;font color=&quot;#2040a0&quot;&gt;destinationfile&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;)&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

   &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;Upload successful!&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt; &lt;strong&gt;else&lt;/strong&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
   &lt;font color=&quot;#2040a0&quot;&gt;echo&lt;/font&gt; &lt;font color=&quot;#008000&quot;&gt;&amp;quot;File attack!&lt;font color=&quot;#77dd77&quot;&gt;\n&lt;/font&gt;&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
?&lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt;
&lt;/pre&gt;&lt;br /&gt;
Here we have destination directory for our uploads - $dir = &#39;/var/www/files/&#39;. Our file will be saved in this directory and will have the name of the uploaded file.&lt;br /&gt;
The function move_uploaded_file checks if the file (first parameter) is a valid uploaded file and if its valid it moves it to $destinationfile. If you just want to check the file without moving it use is_uploaded_file instead.&lt;br /&gt;
And that’s all. Now if you have done everything the right way you must see “Upload successful!” when you use upload_file.php and upload file. &lt;br /&gt;
&lt;br /&gt;
The original of this tutorial is here &lt;a href=&quot;http://ldeveloper.blogspot.com/2011/08/php-and-handling-file-uploads-easy.html&quot;&gt;http://ldeveloper.blogspot.com/2011/08/php-and-handling-file-uploads-easy.html&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2011/08/php-and-handling-file-uploads-easy.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-5106575348785590936</guid><pubDate>Tue, 16 Aug 2011 11:40:00 +0000</pubDate><atom:updated>2011-08-16T04:44:46.235-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PHP</category><title>PHP: Playing with StdClass</title><description>What is StdClass and where does it live?&lt;br /&gt;
&lt;br /&gt;
StdClass is a document class in PHP with no predefined members. Its the class that is created when you cast something to object like this:&lt;br /&gt;
&lt;br /&gt;
$obj = (object) $something;&lt;br /&gt;
&lt;br /&gt;
Sounds good but how to get its members if we don’t know about them? Actually, its very easy and we have several approaches.&lt;br /&gt;
&lt;br /&gt;
First, we can iterate through its members with foreach:&lt;br /&gt;
&lt;pre&gt;foreach ($obj as $key =&amp;gt; $value) {
   
}
&lt;/pre&gt;Second we can cast our object to array:&lt;br /&gt;
&lt;br /&gt;
$array = (array) $obj;&lt;br /&gt;
&lt;br /&gt;
Or get its members as array:&lt;br /&gt;
&lt;br /&gt;
get_object_vars($obj);&lt;br /&gt;
&lt;br /&gt;
What else we can do with StdClass?&lt;br /&gt;
We can create objects and assign members:&lt;br /&gt;
&lt;pre&gt;$std = new StdClass();
$std-&amp;gt;key = &quot;value&quot;;
&lt;/pre&gt;and access them:&lt;br /&gt;
&lt;pre&gt;echo $std-&amp;gt;key;
&lt;/pre&gt;If you see an error like this:&lt;br /&gt;
Catchable fatal error: Object of class stdClass could not be converted to string&lt;br /&gt;
the culprit is our stdClass of course. Maybe you are trying to print an object of this class.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://ldeveloper.blogspot.com/2011/08/how-to-use-soap-with-php-very-simple.html&quot;&gt;Read how to use SOAP with PHP&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2011/08/php-playing-with-stdclass.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-7724650724716317471</guid><pubDate>Thu, 11 Aug 2011 13:36:00 +0000</pubDate><atom:updated>2011-08-11T06:36:46.154-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PHP</category><category domain="http://www.blogger.com/atom/ns#">SOAP</category><title>How to use SOAP with PHP - very simple tutorial and example</title><description>Using SOAP with PHP can be very easy if you do everything right. First your PHP must be configured with --enable-soap. With Windows and WAMP you only need to check PHP &gt; PHP extensions -&gt; php_soap. You can read more about the configuration here http://www.php.net/manual/en/soap.configuration.php but most likely you don’t need to do anything else.&lt;br /&gt;
&lt;br /&gt;
$client = new SoapClient(&quot;http://localhost/SomeSoap.wsdl&quot;);&lt;br /&gt;
$something =  $client-&gt;SomeFunction();&lt;br /&gt;
var_dump($something);&lt;br /&gt;
&lt;br /&gt;
And that’s all.&lt;br /&gt;
If you get Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in the row of&lt;br /&gt;
$something =  $client-&gt;SomeFunction();&lt;br /&gt;
your problem may be in your soap configuration or something like &lt;a href=&quot;http://ldeveloper.blogspot.com/2011/08/php-fatal-error-uncaught-soapfault.html&quot;&gt;this&lt;/a&gt;.</description><link>http://ldeveloper.blogspot.com/2011/08/how-to-use-soap-with-php-very-simple.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-2627678823043760589</guid><pubDate>Thu, 11 Aug 2011 12:45:00 +0000</pubDate><atom:updated>2011-08-11T05:45:54.277-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Random</category><title>How to stop Skype from using port 80</title><description>Its very annoying when you want to use port 80 with apache for example and you must stop Skype, start the service and start Skype again.&lt;br /&gt;
Also its annoying when you install WAMP Server and its not working or at least apache is not working because Skype is on port 80 and you’ve totally forgotten about it. If you are little absent minded like me, you may spend even few hours looking for the problem and installing WAMP again.&lt;br /&gt;
&lt;br /&gt;
Open Skype, select Tools from the menu, then Options, go to Advanced Settings and then Connection. There is a checkbox with the text&lt;br /&gt;
Use port 80 and 443 as alternatives for incoming connections&lt;br /&gt;
Uncheck it and hit Save. That’s it. You may need to restart Skype for the changes to take effect. I hope that this will help you.</description><link>http://ldeveloper.blogspot.com/2011/08/how-to-stop-skype-from-using-port-80.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-4485762478783182616</guid><pubDate>Thu, 11 Aug 2011 07:37:00 +0000</pubDate><atom:updated>2011-08-11T00:39:53.083-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PHP</category><category domain="http://www.blogger.com/atom/ns#">SOAP</category><title>PHP - Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in …</title><description>I receive this nasty error yesterday and it took me some time to figure out the problem. This line passes without any problems&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: #38761d;&quot;&gt;$client = new SoapClient($url);&lt;/div&gt;&lt;br /&gt;
and this&lt;br /&gt;
&lt;div style=&quot;color: #38761d;&quot;&gt;&lt;br /&gt;
var_dump($client-&amp;gt;__getFunctions());&lt;/div&gt;&lt;br /&gt;
shows the function prototypes correctly. So it connects and gets the data but when I try to call a function I receive this error&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Fatal error: Uncaught SoapFault exception: [HTTP] Could not connect to host in MyFile.php:23 Stack trace: #0 [internal function]: SoapClient-&amp;gt;__doRequest(&#39;__call(&#39;myFunction&#39;, Array) #2 …&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
I made fast research and found that people receive this error when their php installation isn’t right or because they are trying to use it with https without the openSSL extension. So you can receive this problem with various situations. Anyway my code was right so I took a look at the service description that I received from the server and there was the problem. The server wasn’t configured right&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;service&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&#39;myService&#39;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 ...
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;soap:address&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;location=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&#39;http://some_other_url&#39;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 ..
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/service&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;br /&gt;
It was configured to send invalid url and the function calls were using that invalid url. So there are two solutions - one correct and one that is almost correct but it works for testing purposes when you wait for people to fix their server. So the first is to configure the server correctly. The other is to give __doReguest the correct location.&lt;br /&gt;
I hope this will help somebody because founding the problem was very frustrating for me. &lt;/soap:address&gt;</description><link>http://ldeveloper.blogspot.com/2011/08/php-fatal-error-uncaught-soapfault.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-7884719621051176671</guid><pubDate>Mon, 30 Nov 2009 17:47:00 +0000</pubDate><atom:updated>2009-11-30T09:47:24.100-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>Walking around with JQuery</title><description>Selecting, traversing, and manipulating DOM elements is relatively easy with JQuery. You can play with them and do many cool things. &lt;br /&gt;
&lt;br /&gt;
Let’s start with simple selecting. We may need a list of all the images in a document. This can be achieved very easy:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt; $(&quot;img&quot;)
&lt;/pre&gt;&lt;/div&gt;Let’s hide them:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;img&quot;).hide();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
Now, if we don’t want all images but only images located in div tag we can do this:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;div &amp;gt; img&quot;).hide();
&lt;/pre&gt;&lt;/div&gt;Selecting element with a specific id is very simple:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;#myId&quot;)
&lt;/pre&gt;&lt;/div&gt;And we can obtain a list of images located in this specific div with the expression:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;#myId &amp;gt; img&quot;)
&lt;/pre&gt;&lt;/div&gt;We can get a list of elements from a certain type and having a specific class. For example we can get a list of all div elements who have css class text and hide them.&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;div .text&quot;).hide();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
If we get a list of elements from another source (for example some function) and we want to obtain only the ones with a exact property we can do it with filter. In this example I’ll select all div elements and check them:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;       $(&quot;div&quot;).filter(&quot;.text&quot;).hide();
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
After hiding all elements we may want to show the first one. Here we have several approaches. If the circumstances are right we can just select the first element:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;        $(&quot;.text:first&quot;).show();
&lt;/pre&gt;&lt;/div&gt;Of course we may want the last one:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;        $(&quot;.text:last&quot;).show();
&lt;/pre&gt;&lt;/div&gt;We can get the n-th element using eq. Keep in mind that arrays start from 0.&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;        var n = 1; // we want the second element in reality
        $(&quot;div:eq(&quot;+n+&quot;)&quot;).show();
&lt;/pre&gt;&lt;/div&gt;We can obtain all elements on a page that contain a specific text: &lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;        $(&quot;div:contains(text)&quot;). css(&quot;background-color&quot;,&quot;yellow&quot;);
&lt;/pre&gt;&lt;/div&gt;Or we can obtain all div elements containing a specific text (text) and not specific css class:&lt;br /&gt;
&lt;div style=&quot;background-color: linen; border: thin groove; color: black;&quot;&gt;&lt;pre&gt;         $(&quot;div:contains(text):not(.title)&quot;). css(&quot;background-color&quot;,&quot;yellow&quot;);
&lt;/pre&gt;&lt;/div&gt;I’ll continue with more later.</description><link>http://ldeveloper.blogspot.com/2009/11/walking-around-with-jquery.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-5141451332166256279</guid><pubDate>Tue, 17 Nov 2009 06:44:00 +0000</pubDate><atom:updated>2009-11-16T22:44:23.495-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>How to write your own jquery plugins – random size plugin</title><description>Let’s continue our plugin example. I’ll change the &lt;a href=&quot;http://ldeveloper.blogspot.com/2009/11/how-to-write-your-own-jquery-plugins.html&quot;&gt;plugin from the first post&lt;/a&gt; to something a little more fun. &lt;br /&gt;
&lt;br /&gt;
RandomSize plugin – it will change the font size of all inner html elements with random values. For this goal we need a list of &#39;this&#39; element children. &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;var c = $(this).children();&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
We can generate random numbers with the expression:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;Math.floor(Math.random() * max)&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
where max is our max value. Also it is better to have a min value because people can’t read font with size 1. So our expression will evolve this way:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;Math.floor(min + Math.random() * (max - min))&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Here is the plugin code:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;(function($) { 
$.fn.randomSize = function(settings) {
    var config = { 
     &#39;min&#39;:&#39;10&#39;, 
  &#39;max&#39;:&#39;30&#39;,
  &#39;fontWeight&#39; : &#39;bolder&#39;};
    
     if (settings) 
      $.extend(config, settings);
 
     this.each(function() {
  var c = $(this).children();
  c.each(function() {
   var rand = Math.floor(
    parseInt(config.min) + 
    (Math.random() * 
    (config.max - config.min)));
    
   var cssObj = { 
       &#39;font-size&#39;:rand + &#39;px&#39;, 
       &#39;font-weight&#39;:config.fontWeight};
   $(this).css(cssObj);
  });
   
     });
 
     return this;
};
})(jQuery);
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
Sample html:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Element 1&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Element 2&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Element 3&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/span&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And we call it like this:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;$(&quot;div&quot;).randomSize();&lt;br /&gt;
&lt;/div&gt;</description><link>http://ldeveloper.blogspot.com/2009/11/how-to-write-your-own-jquery-plugins_16.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-2691477959836225431</guid><pubDate>Mon, 16 Nov 2009 08:51:00 +0000</pubDate><atom:updated>2009-11-16T22:45:25.893-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>How to write your own jQuery plugins</title><description>Packing your code into plugins will make it easier for maintenance and reuse. JQuery plugins can accelerate the development process and simplify the final product. Writing your own plugins isn’t hard either. &lt;br /&gt;
&lt;br /&gt;
Ok, let’s start with a very simple plugin. I have very little imagination, so my plugin will do very stupid work – it will change the font size and weight of an element. I’ll call it … demoPlugin. Original, isn’t it?&lt;br /&gt;
&lt;br /&gt;
Let’s define it:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$.fn.demoPlugin &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; function(settings) &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;And we will call it this way:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;div&amp;quot;&lt;/font&gt;).demoPlugin()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;Some initial configuration like this:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;var&lt;/strong&gt; config &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&#39;fontSize&#39;&lt;/font&gt; : &lt;font color=&quot;#008000&quot;&gt;&#39;30px&#39;&lt;/font&gt;, &lt;font color=&quot;#008000&quot;&gt;&#39;fontWeight&#39;&lt;/font&gt; : &lt;font color=&quot;#008000&quot;&gt;&#39;bolder&#39;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;And we will extend it with the parameters provided by the user.&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;if&lt;/strong&gt; (settings) 
 $.extend(config, settings)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;And our main code goes here:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;this&lt;/strong&gt;.each(function() &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
   $(&lt;strong&gt;this&lt;/strong&gt;).css(&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

      &lt;font color=&quot;#008000&quot;&gt;&#39;font-size&#39;&lt;/font&gt;:config.fontSize, 
      &lt;font color=&quot;#008000&quot;&gt;&#39;font-weight&#39;&lt;/font&gt;:config.fontWeight&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
       &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;Here is the full plugin code:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;(function($) &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt; 
 $.fn.demoPlugin &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; function(settings) &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

   &lt;strong&gt;var&lt;/strong&gt; config &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#008000&quot;&gt;&#39;fontSize&#39;&lt;/font&gt; : &lt;font color=&quot;#008000&quot;&gt;&#39;30px&#39;&lt;/font&gt;, 
    &lt;font color=&quot;#008000&quot;&gt;&#39;fontWeight&#39;&lt;/font&gt; : &lt;font color=&quot;#008000&quot;&gt;&#39;bolder&#39;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

       &lt;strong&gt;if&lt;/strong&gt; (settings) 
    $.extend(config, settings)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 
       &lt;strong&gt;this&lt;/strong&gt;.each(function() &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
   $(&lt;strong&gt;this&lt;/strong&gt;).css(&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

      &lt;font color=&quot;#008000&quot;&gt;&#39;font-size&#39;&lt;/font&gt;:config.fontSize, 
      &lt;font color=&quot;#008000&quot;&gt;&#39;font-weight&#39;&lt;/font&gt;:config.fontWeight&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
       &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 
       &lt;strong&gt;return&lt;/strong&gt; &lt;strong&gt;this&lt;/strong&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

  &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)(jQuery)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
Don&#39;t forget to return this at the end. It is very important in order to use chain calls.&lt;br /&gt;
&lt;br /&gt;
I’ll continue with less trivial plugin example later.&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://ldeveloper.blogspot.com/2009/11/how-to-write-your-own-jquery-plugins_16.html&quot;&gt;Next plugin article.&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2009/11/how-to-write-your-own-jquery-plugins.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-6906624869239827867</guid><pubDate>Sat, 07 Nov 2009 14:14:00 +0000</pubDate><atom:updated>2009-11-07T06:14:52.176-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>Selecting elements with JQuery – examples</title><description>JQuery Library is a very convenient way for selecting page elements. You can select elements by type, by parent, by index and so on. &lt;br /&gt;
The easiest way to select an item is by its id. I’ll use it for my control buttons. For all three of them I’ll bind functions to their click event. &lt;br /&gt;
Here are my buttons as HTML code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;all&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide ALL&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nth&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide nth&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;odd&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide ODD&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And my test javascript code here:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$(&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;document&lt;/strong&gt;&lt;/font&gt;).ready(function() &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;#all&amp;quot;&lt;/font&gt;).&lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;click&lt;/strong&gt;&lt;/font&gt;(function () &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;alert&lt;/strong&gt;&lt;/font&gt;(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;Clicked ALL&amp;quot;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;#nth&amp;quot;&lt;/font&gt;).&lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;click&lt;/strong&gt;&lt;/font&gt;(function () &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;alert&lt;/strong&gt;&lt;/font&gt;(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;Clicked NTH&amp;quot;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;#odd&amp;quot;&lt;/font&gt;).&lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;click&lt;/strong&gt;&lt;/font&gt;(function () &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;alert&lt;/strong&gt;&lt;/font&gt;(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;Clicked ODD&amp;quot;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
Now we will change the code to select and toggle the desired elements. We will start with the first because it is the easiest of them all. Selecting elements by type in JQuery is very simple and is done through their name. To select all paragraphs we simply need to use $(&quot;p&quot;) and call toggle on it. $(&quot;p&quot;) will return all matched elements – all ‘p’ tags on the page.&lt;br /&gt;
The code:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;#all&amp;quot;&lt;/font&gt;).&lt;font color=&quot;a52a2a&quot;&gt;&lt;strong&gt;click&lt;/strong&gt;&lt;/font&gt;(function () &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&amp;quot;p&amp;quot;&lt;/font&gt;).toggle()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
To select the n-th element – in our case the third one we will use $(&quot;p:eq(3)&quot;) and to select all odd paragraphs $(&quot;p:odd&quot;). &lt;br /&gt;
&lt;br /&gt;
Here is the full example code:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Selecting elements with JQuery&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;script&lt;/font&gt;  &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;jquery.js&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
$(document).ready(function() {
 $(&amp;quot;#all&amp;quot;).click(function () {
  $(&amp;quot;p&amp;quot;).toggle();
 });
 $(&amp;quot;#nth&amp;quot;).click(function () {
  $(&amp;quot;p:eq(3)&amp;quot;).toggle();
 });
 $(&amp;quot;#odd&amp;quot;).click(function () {
  $(&amp;quot;p:odd&amp;quot;).toggle();
 });
});
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
JQuery example - selecting items.
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Paragraph 0&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Paragraph 1&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Paragraph 2&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Paragraph 3&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Paragraph 4&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/p&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;table&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;All Paragraphs: &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;all&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide ALL&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Third paragraph: &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nth&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide nth&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;All odd paragraphs: &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;button&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;odd&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Show/Hide ODD&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/button&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/td&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/tr&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/table&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
As you can see – very simple and intuitive.</description><link>http://ldeveloper.blogspot.com/2009/11/selecting-elements-with-jquery-examples.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-8040840268080896436</guid><pubDate>Mon, 02 Nov 2009 15:21:00 +0000</pubDate><atom:updated>2009-11-04T11:17:54.111-08:00</atom:updated><title>How to make very simple JavaScript slideshow with JQuery</title><description>I’ll continue my article about &lt;a href=&quot;http://ldeveloper.blogspot.com/2007/10/fun-with-jquery-effects-few-examples.html&quot;&gt;JQuery Effects&lt;/a&gt; - with this one. It would be short information on how to make custom JQuery slideshow animation. &lt;br /&gt;
&lt;br /&gt;
Let’s start with a div containing our images. Here is the code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;div&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;slideshow&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img1.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img2.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img3.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img4.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img5.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img6.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
I’m not really good at using CSS so it would be pretty simple.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;#slideshow {
    position:relative;
    height:200px;
    width: 210px;
}
#slideshow img {
    position:absolute;
    top:10px;
    left:5px;
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
I’ll use some initializing code to hide all the images, and then I’ll show only the first one. Here is the code packed in a function. &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;function&lt;font color=&quot;ff0000&quot;&gt; init&lt;/font&gt;&lt;font color=&quot;2040a0&quot;&gt;()&lt;/font&gt; {&lt;/strong&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img&#39;&lt;/font&gt;).hide()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:first&#39;&lt;/font&gt;).show()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And now, we must write the logic of our slideshow. We need to obtain the visible image, hide it and show the next one. When we hit the end, we need to revert back at the first element. &lt;br /&gt;
So let’s start with obtaining the visible image. It is simple with JQuery selectors:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;var&lt;/strong&gt; $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:visible&#39;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And get the next image:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$next &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.next()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
This won’t help us when we reach the last image. I’ll make a check for the last element:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;strong&gt;var&lt;/strong&gt; $next&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;strong&gt;if&lt;/strong&gt;($&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.next().&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;length&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt; &lt;font color=&quot;#FF0000&quot;&gt;0&lt;/font&gt;)
  $next &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.next()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 &lt;strong&gt;else&lt;/strong&gt;
         $next &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:first&#39;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And now the action:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;$&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.hide()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
$next.show()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
Our slide function must be called on a regular basis. We will obtain this with the JS function setInterval.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;setInterval( &lt;font color=&quot;#008000&quot;&gt;&amp;quot;slide()&amp;quot;&lt;/font&gt;, &lt;font color=&quot;#FF0000&quot;&gt;3000&lt;/font&gt; )&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And here is the full code:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;JQuery Slideshow examples&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;style&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

#slideshow {
    position:relative;
    height:200px;
 width: 210px;
}
#slideshow img {
    position:absolute;
    top:10px;
    left:5px;
}
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/style&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;script&lt;/font&gt;  &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;jquery.js&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;strong&gt;function&lt;font color=&quot;ff0000&quot;&gt; init&lt;/font&gt;&lt;font color=&quot;2040a0&quot;&gt;()&lt;/font&gt; {&lt;/strong&gt;
 $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img&#39;&lt;/font&gt;).hide()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:first&#39;&lt;/font&gt;).show()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;strong&gt;function&lt;font color=&quot;ff0000&quot;&gt; slide&lt;/font&gt;&lt;font color=&quot;2040a0&quot;&gt;()&lt;/font&gt; {&lt;/strong&gt;
    &lt;strong&gt;var&lt;/strong&gt; $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:visible&#39;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

    &lt;strong&gt;var&lt;/strong&gt; $next&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;strong&gt;if&lt;/strong&gt;($&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.next().&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;length&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&amp;gt;&lt;/font&gt; &lt;font color=&quot;#FF0000&quot;&gt;0&lt;/font&gt;)
  $next &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.next()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 &lt;strong&gt;else&lt;/strong&gt;
        $next &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; $(&lt;font color=&quot;#008000&quot;&gt;&#39;#slideshow img:first&#39;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 $&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;top&lt;/strong&gt;&lt;/font&gt;.hide()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 $next.show()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;

$(&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;document&lt;/strong&gt;&lt;/font&gt;).ready(function() &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
 init()&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
    setInterval( &lt;font color=&quot;#008000&quot;&gt;&amp;quot;slide()&amp;quot;&lt;/font&gt;, &lt;font color=&quot;#FF0000&quot;&gt;3000&lt;/font&gt; )&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;)&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/script&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;div&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;id=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;slideshow&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img1.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img2.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img3.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img4.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img5.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;img&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;src=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;img6.jpg&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/div&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a rel=&quot;nofollow&quot; target=&quot;_blank&quot; href=&quot;http://ldeveloper.hit.bg/slideshow%20example.htm&quot;&gt;Working demo&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2009/11/how-to-make-very-simple-javascript.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-3367928166544570726</guid><pubDate>Tue, 27 Oct 2009 18:47:00 +0000</pubDate><atom:updated>2009-10-27T11:50:07.129-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">examples</category><category domain="http://www.blogger.com/atom/ns#">Java</category><category domain="http://www.blogger.com/atom/ns#">struts</category><title>Intro to Struts (1.x) - Practical Example</title><description>This would be simple and easy tutorial on how to use Apache Struts in Java web projects.&lt;br /&gt;
&lt;br /&gt;
What do you need for this tutorial?&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;Java &lt;/li&gt;
&lt;li&gt;Tomcat&lt;/li&gt;
&lt;li&gt;Java IDE (For example Eclipse or NetBeans)&lt;/li&gt;
&lt;li&gt;Struts 1.x version http://struts.apache.org/download.cgi#struts1310&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
I’ll write another document for Struts 2.x. They are different frameworks with somehow different ideas but both are excellent choice. &lt;br /&gt;
&lt;br /&gt;
For clearness it would be very simple code - I won’t use packages or other good practices. Consider this only as an introduction not a reference. &lt;br /&gt;
&lt;br /&gt;
Struts programming is centered at the MVC pattern. MVC stands for Model-View-Controller, an idea to separate the business logic, application data and the presentation layer. I won’t discuss here what the advantages of using MVC architecture in web application are – just make a fast search, there is plenty of information out there.&lt;br /&gt;
&lt;br /&gt;
Let’s start with creating a new project. Our web application would ask visitors for a name and redirect them to a Hi! page. At part 2 it won’t like some of the visitors and will return back them with an error message.&lt;br /&gt;
&lt;br /&gt;
Here is my directory and file structure for Struts1Example project:&lt;br /&gt;
&lt;pre&gt;Struts1Example
 src
  NameAction.java
  NameActionForm.java
 webroot
  WEB-INF
   classes
   lib
   struts-config.xml
   web.xml
  ask.jsp
  greet.jsp
&lt;/pre&gt;&lt;br /&gt;
Lets start with writing our ActionForm – I’ll name the class NameActionForm. It would be very plain – only one field and a setter-getter pair. Here is the code:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NameActionForm.java&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import javax.servlet.http.HttpServletRequest;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.ActionForm;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.ActionMapping;&lt;/strong&gt;&lt;/font&gt;


&lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;class&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;NameActionForm&lt;/font&gt; &lt;strong&gt;extends&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;ActionForm&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
 &lt;strong&gt;private&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;String&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;strong&gt;null&lt;/strong&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;

 
 &lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;void&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;reset&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;ActionMapping&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;mapping&lt;/font&gt;, 
    &lt;font color=&quot;#2040a0&quot;&gt;HttpServletRequest&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;request&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

        &lt;strong&gt;this&lt;/strong&gt;.&lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;strong&gt;null&lt;/strong&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;

 &lt;strong&gt;public&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;String&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;getName&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

  &lt;strong&gt;return&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;

 &lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;void&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;setName&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;String&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

  &lt;strong&gt;this&lt;/strong&gt;.&lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;=&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And our action:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;NameAction.java&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import javax.servlet.http.HttpServletRequest;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import javax.servlet.http.HttpServletResponse;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.Action;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.ActionForm;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.ActionForward;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;0000ff&quot;&gt;&lt;strong&gt;import org.apache.struts.action.ActionMapping;&lt;/strong&gt;&lt;/font&gt;

&lt;strong&gt;public&lt;/strong&gt; &lt;strong&gt;class&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;NameAction&lt;/font&gt; &lt;strong&gt;extends&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;Action&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;

 &lt;strong&gt;public&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;ActionForward&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;execute&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;ActionMapping&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;mapping&lt;/font&gt;, 
    &lt;font color=&quot;#2040a0&quot;&gt;ActionForm&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;form&lt;/font&gt;,
    &lt;font color=&quot;#2040a0&quot;&gt;HttpServletRequest&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;request&lt;/font&gt;, 
    &lt;font color=&quot;#2040a0&quot;&gt;HttpServletResponse&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;response&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;{&lt;/strong&gt;&lt;/font&gt;
  &lt;strong&gt;return&lt;/strong&gt; &lt;font color=&quot;#2040a0&quot;&gt;mapping&lt;/font&gt;.&lt;font color=&quot;#2040a0&quot;&gt;findForward&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;(&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;success&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;)&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;;&lt;/font&gt;
 &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;}&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
In Struts the Action class goal is to process a request, do the logic and pass a forward object (ActionForward). Our Action is very simple – it is doing nothing, just passes our forward object. The “success” forward is defined in our struts-config.xml.&lt;br /&gt;
&lt;br /&gt;
We will have two jsp files – ask.jsp and greet.jsp. In ask.jsp we will ask visitors for a name.&lt;br /&gt;
&lt;b&gt;ask.jsp&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;%@&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;page&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;language=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;java&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;contentType=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;text/html; 
  charset=utf-8&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;%&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;%@&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;taglib&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;uri=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;http://struts.apache.org/tags-html&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
  prefix=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;html&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;%&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html:html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Say Hi!&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html:form&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;action=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nameAction&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
  What&#39;s your name?
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html:text&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;property=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;name&amp;quot;&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html:text&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html:submit&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Send!&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html:submit&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html:form&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html:html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;greet.jsp&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;%@&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;page&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;language=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;java&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;contentType=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;text/html; 
  charset=utf-8&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;%&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;%@&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;taglib&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;uri=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;http://struts.apache.org/tags-bean&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
  prefix=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;bean&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;%&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;%@&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;taglib&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;uri=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;http://struts.apache.org/tags-html&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;

  prefix=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;html&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;%&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;html:html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Say Hi!&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/title&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/head&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

Hi, &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;bean:write&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nameForm&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;property=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;name&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/body&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/html:html&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And now the cool part – web.xml&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;web.xml&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;?xml&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;version=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;?&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;web-app&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;display-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;Struts 1x Example&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/display-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;servlet&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;servlet-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;action&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/servlet-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;servlet-class&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
     org.apache.struts.action.ActionServlet
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/servlet-class&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;init-param&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

      &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;param-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;config&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/param-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
      &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;param-value&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
       /WEB-INF/struts-config.xml
      &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/param-value&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/init-param&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;load-on-startup&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;2&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/load-on-startup&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

 &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/servlet&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;servlet-mapping&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;servlet-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;action&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/servlet-name&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;url-pattern&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;*.do&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/url-pattern&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/servlet-mapping&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;welcome-file-list&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;welcome-file&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;index.jsp&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/welcome-file&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
  &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/welcome-file-list&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/web-app&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
And our struts configuration – struts-config.xml&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;struts-config.xml&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;pre&gt;&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;?xml&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;version=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;1.0&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;?&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;struts-config&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;form-beans&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
     &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;form-bean&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;    &lt;font color=&quot;#2040a0&quot;&gt;  name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nameForm&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;    &lt;font color=&quot;#2040a0&quot;&gt;  type=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;NameActionForm&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/form-beans&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;global-forwards&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
        &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;forward
&lt;/font&gt;            &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;/nameAction&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;            &lt;font color=&quot;#2040a0&quot;&gt;path=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;/nameAction.do&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/global-forwards&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;action-mappings&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;         
       &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;action&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;path=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;/nameAction&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;      &lt;font color=&quot;#2040a0&quot;&gt;   type=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;NameAction&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;

&lt;/font&gt;      &lt;font color=&quot;#2040a0&quot;&gt;   input=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;ask.jsp&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;      &lt;font color=&quot;#2040a0&quot;&gt;    name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;nameForm&amp;quot;&lt;/font&gt; &lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
        &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;forward&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;success&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;

&lt;/font&gt;      &lt;font color=&quot;#2040a0&quot;&gt;    path=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;/greet.jsp&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
        &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;forward&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;name=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;failure&amp;quot;&lt;/font&gt; &lt;font color=&quot;#2040a0&quot;&gt;
&lt;/font&gt;      &lt;font color=&quot;#2040a0&quot;&gt;    path=&lt;/font&gt;&lt;font color=&quot;#008000&quot;&gt;&amp;quot;/ask.jsp&amp;quot;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;

       &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/action&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
    &lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/action-mappings&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;font color=&quot;#2040a0&quot;&gt;&lt;strong&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;lt;&lt;/strong&gt;&lt;/font&gt;&lt;font color=&quot;#2040a0&quot;&gt;/struts-config&lt;/font&gt;&lt;font color=&quot;4444FF&quot;&gt;&lt;strong&gt;&amp;gt;&lt;/strong&gt;&lt;/font&gt;&lt;/strong&gt;&lt;/font&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;
struts-config.xml is used to initialize Struts. It describes the action mappings for the project and must be placed in the WEB-INF directory. We have a form-bean tag describing our NameActionForm and an action-mapping for our NameAction.&lt;br /&gt;
&lt;br /&gt;
This is our base code. In some future post I’ll add field validation, error handling and some other good stuff.</description><link>http://ldeveloper.blogspot.com/2009/10/intro-to-struts-1x-practical-example.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-2634457475452438857</guid><pubDate>Thu, 22 Oct 2009 09:23:00 +0000</pubDate><atom:updated>2009-10-22T03:04:31.543-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>Fun with JQuery Effects – few examples</title><description>You can use JQuery Effects in many different ways. I&#39;ll write few examples just to show how cool and fun is to work with this API. &lt;br /&gt;
&lt;br /&gt;
Using toggle:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;toggle.html&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;JQuery examples&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;style&amp;gt;&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;script  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
$(document).ready(function() {&lt;br /&gt;
$(&amp;quot;#our_button&amp;quot;).click(function() {&lt;br /&gt;
&lt;b&gt;$(&amp;quot;#our_image&amp;quot;).toggle();&lt;/b&gt;&lt;br /&gt;
});&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;button id=&amp;quot;our_button&amp;quot;&amp;gt;Hide/Show&amp;lt;/button&amp;gt; the image.&lt;br /&gt;
&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;our_image&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;img border=&amp;quot;0&amp;quot; src=&amp;quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSMhLVeVRnBTwKXkBjFX-nOQusSJyKsneDo-yTxCWJtDGVFg2FMzr4vSEWTDjCm7WgGWW1KFYadgz0y3gyXd7kuBMcMIlWijcK3ikxqRVciTwJWdaaiT6Z62m6pGWQNhKILC2oWF4Hmw/s320/flower.jpg&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 250, 250); color: Black;&quot;&gt;&lt;script src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script&gt;
$(document).ready(function() {
 $(&quot;#our_button1&quot;).click(function() {
  $(&quot;#our_image1&quot;).toggle();
 });
});
&lt;/script&gt;&lt;br /&gt;
&lt;button id=&quot;our_button1&quot;&gt;Hide/Show&lt;/button&gt; the image.&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;our_image1&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSMhLVeVRnBTwKXkBjFX-nOQusSJyKsneDo-yTxCWJtDGVFg2FMzr4vSEWTDjCm7WgGWW1KFYadgz0y3gyXd7kuBMcMIlWijcK3ikxqRVciTwJWdaaiT6Z62m6pGWQNhKILC2oWF4Hmw/s320/flower.jpg&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Using slide toggle:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;slide.html&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;JQuery examples&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;style&amp;gt;&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;script  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
$(document).ready(function() {&lt;br /&gt;
$(&amp;quot;#our_button&amp;quot;).click(function() {&lt;br /&gt;
&lt;b&gt;$(&amp;quot;#our_image&amp;quot;).slideToggle(&quot;slow&quot;);&lt;/b&gt;&lt;br /&gt;
});&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;/p&gt;&lt;p&gt;&amp;lt;button id=&amp;quot;our_button&amp;quot;&amp;gt;Hide/Show&amp;lt;/button&amp;gt; the image.&lt;br /&gt;
&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;div id=&amp;quot;our_image&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;img border=&amp;quot;0&amp;quot; src=&amp;quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSMhLVeVRnBTwKXkBjFX-nOQusSJyKsneDo-yTxCWJtDGVFg2FMzr4vSEWTDjCm7WgGWW1KFYadgz0y3gyXd7kuBMcMIlWijcK3ikxqRVciTwJWdaaiT6Z62m6pGWQNhKILC2oWF4Hmw/s320/flower.jpg&amp;quot; /&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
And the result:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 250, 250); color: Black;&quot;&gt;&lt;script src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script&gt;
$(document).ready(function() {
 $(&quot;#our_button2&quot;).click(function() {
  $(&quot;#our_image2&quot;).slideToggle(&quot;slow&quot;);
 });
});
&lt;/script&gt;&lt;br /&gt;
&lt;button id=&quot;our_button2&quot;&gt;Slide in/out&lt;/button&gt; the image.&lt;br /&gt;
&lt;br /&gt;
&lt;div id=&quot;our_image2&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSMhLVeVRnBTwKXkBjFX-nOQusSJyKsneDo-yTxCWJtDGVFg2FMzr4vSEWTDjCm7WgGWW1KFYadgz0y3gyXd7kuBMcMIlWijcK3ikxqRVciTwJWdaaiT6Z62m6pGWQNhKILC2oWF4Hmw/s320/flower.jpg&quot; /&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
Easy, isn&#39;t it? Tomorrow I&#39;ll continue with animate function.</description><link>http://ldeveloper.blogspot.com/2007/10/fun-with-jquery-effects-few-examples.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSMhLVeVRnBTwKXkBjFX-nOQusSJyKsneDo-yTxCWJtDGVFg2FMzr4vSEWTDjCm7WgGWW1KFYadgz0y3gyXd7kuBMcMIlWijcK3ikxqRVciTwJWdaaiT6Z62m6pGWQNhKILC2oWF4Hmw/s72-c/flower.jpg" height="72" width="72"/><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-5784234049158731177</guid><pubDate>Mon, 12 Oct 2009 08:04:00 +0000</pubDate><atom:updated>2009-10-12T01:11:47.557-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>More JQuery examples - Intro to JQuery - part 3</title><description>&lt;b&gt;How to use JQuery filter? (Easy example)&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Filter is used to filter some results from a set. (of course) For example let’s have a document with many divs in it. We want to select only the ones with css class “.text” and hide them. We can do this using filter. &lt;br /&gt;
&lt;br /&gt;
At the beginning lets write some dummy html file with the basics in it. Here it is our &lt;b&gt;filter.htm&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;p&gt;&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;Our JQuery examples&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;style&amp;gt;&lt;br /&gt;
.text {&lt;br /&gt;
} &lt;br /&gt;
.comment {&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;script  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;script&amp;gt;&lt;br /&gt;
$(document).ready(function(){&lt;br /&gt;
// our javascript examples will go here&lt;br /&gt;
});&lt;br /&gt;
&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;!-- our text will go here --&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
Let’s make some divs and set class text to some of them and comment to the others. &lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&amp;lt;div class=&amp;quot;comment&amp;quot;&amp;gt;&lt;br /&gt;
123&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
This will be selected.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;comment&amp;quot;&amp;gt;&lt;br /&gt;
This wont be selected.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
This div will be selected.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;&lt;br /&gt;
Selected!&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
This row will hide all divs with class text.&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;$(&quot;div&quot;).filter(&quot;.text&quot;).hide();&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
It would be easy to make a button that shows and hides these divs. Here is the full source:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;p&gt;&amp;lt;html&amp;gt;  &lt;br /&gt;
&amp;lt;head&amp;gt;  &lt;br /&gt;
&amp;lt;title&amp;gt;Our JQuery examples&amp;lt;/title&amp;gt;  &lt;br /&gt;
&amp;lt;style&amp;gt;  &lt;br /&gt;
.&lt;b&gt;text&lt;/b&gt; {  &lt;br /&gt;
&lt;br /&gt;
}&lt;/p&gt;&lt;p&gt;.comment {&lt;/p&gt;&lt;p&gt;}  &lt;br /&gt;
&amp;lt;/style&amp;gt;  &lt;br /&gt;
&amp;lt;script  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;  &lt;br /&gt;
&amp;lt;script&amp;gt;  &lt;br /&gt;
$(document).ready(function() {  &lt;br /&gt;
&lt;b&gt;$(&amp;quot;#toggle&amp;quot;).click(function() {  &lt;br /&gt;
$(&amp;quot;div&amp;quot;).filter(&amp;quot;.text&amp;quot;).toggle(); &lt;br /&gt;
});&lt;/b&gt;  &lt;br /&gt;
});  &lt;br /&gt;
&amp;lt;/script&amp;gt;  &lt;br /&gt;
&amp;lt;/head&amp;gt;  &lt;br /&gt;
&amp;lt;body&amp;gt;  &lt;br /&gt;
Show and hide filtered divs. &amp;lt;br /&amp;gt;  &lt;br /&gt;
&amp;lt;button id=&amp;quot;toggle&amp;quot;&amp;gt;Toggle Show/Hide&amp;lt;/button&amp;gt;  &lt;br /&gt;
&amp;lt;div class=&amp;quot;comment&amp;quot;&amp;gt;  &lt;br /&gt;
123  &lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;  &lt;br /&gt;
This will be selected.  &lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
&amp;lt;div class=&amp;quot;comment&amp;quot;&amp;gt;  &lt;br /&gt;
This wont be selected.  &lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;  &lt;br /&gt;
This div will be selected.  &lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
&amp;lt;div class=&amp;quot;text&amp;quot;&amp;gt;  &lt;br /&gt;
Selected!  &lt;br /&gt;
&amp;lt;/div&amp;gt;  &lt;br /&gt;
&amp;lt;/body&amp;gt;  &lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
Here is our work:&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 250, 250); color: Black;&quot;&gt;&lt;script src=&quot;http://code.jquery.com/jquery-latest.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;
&lt;script &gt;
$(document).ready(function() {
$(&quot;#toggle&quot;).click(function() {
 $(&quot;div&quot;).filter(&quot;.jquery_text&quot;).toggle();
});
});
&lt;/script&gt;&lt;br /&gt;
Show and hide filtered divs. &lt;br /&gt;
&lt;button id=&quot;toggle&quot;&gt;Toggle Show/Hide&lt;/button&gt;&lt;br /&gt;
&lt;div class=&quot;jquery_comment&quot;&gt;123&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;jquery_text&quot;&gt;This will be selected.&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;jquery_comment&quot;&gt;This wont be selected.&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;jquery_text&quot;&gt;This div will be selected.&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;jquery_text&quot;&gt;Selected!&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;a href=&quot;http://ldeveloper.blogspot.com/2008/10/intro-to-jquery-basic-tutorial.html&quot;&gt;Intro to JQuery - part 1&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://ldeveloper.blogspot.com/2008/11/intro-to-jquery-part-2-jquery-examples.html&quot;&gt;Intro to JQuery - part 2&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2009/10/more-jquery-examples.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-8456431533891271427</guid><pubDate>Sun, 13 Sep 2009 12:11:00 +0000</pubDate><atom:updated>2009-09-13T05:13:49.924-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">security</category><title>Web authorization and OAuth</title><description>&lt;b&gt;OAuth &lt;/b&gt;is an open protocol that defines secure api authorization methods. More and more sites in internet adopt its idea and start to use it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;So what is so cool about it?&lt;/b&gt;&lt;br /&gt;
OAuth offers a way to work with protected data while securing sensitive user account information. Imagine you want to access your twitter, yahoo or google account from some third party site or application with someadditional functionality. What will happen if the consumer site or application is not so trustworthy and steal your account? OAuth is the key to protect your account in this case.&lt;br /&gt;
There is a very popular parallel in the web. OAuth is like the valet key that offers a limited use of your car. Not all cars came with valet keys but anyway it is a good comparison.&lt;br /&gt;
&lt;br /&gt;
With OAuth the user grants access to his protected resources without sharing his username and password with third parties. Imagine a website that offers you great functionality to add and remove many Twitter followers. One way to use it is to share your credentials with it. The other is to use special token to give only few privileges but to protect your sensitive information.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Some terminology:&lt;/b&gt;&lt;br /&gt;
Service Provider – web service that offers some functionality to third parties.&lt;br /&gt;
Consumers – website or application that accesses protected resources of a Service Provider.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How to use it? Do I need to reinvent the wheel?&lt;/b&gt;&lt;br /&gt;
Nop. The wheel is invented. There are some ready libraries out there. &lt;a href=&quot;http://oauth.net/code&quot;&gt;http://oauth.net/code&lt;/a&gt;&lt;br /&gt;
Here is one useful tool &lt;a href=&quot;http://googlecodesamples.com/oauth_playground/&quot;&gt;http://googlecodesamples.com/oauth_playground/&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on OAuth visit &lt;a href=&quot;http://oauth.net/&quot;&gt;http://oauth.net/&lt;/a&gt; .</description><link>http://ldeveloper.blogspot.com/2009/09/oauth-and-web-authorization.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-3258338378095183572</guid><pubDate>Thu, 13 Nov 2008 11:51:00 +0000</pubDate><atom:updated>2008-11-13T04:13:34.806-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><category domain="http://www.blogger.com/atom/ns#">Web 2.0</category><title>Simple AJAX with JQuery(part 1) – ugly example</title><description>After getting some experience with JQuery from the previous tutorials, you may be ready for some fun. AJAX development is relatively easy with the JQuery framework. &lt;br /&gt;&lt;br /&gt;For this part I’ll show how to use “load” in a basic example. We will have a online book and we will load the chapters without reloading the whole page. This is a stupid example, for many reasons. First – online publishers prefer more reloads. The AJAX functionality is a better decision for online business solutions, not for online reading. But I have no imagination for other relatively simple demo and I am lazy. &lt;br /&gt;&lt;br /&gt;So – our example. It is an online book. We will select our chapter with prev(previos) and next buttons. The full ugly working example can be seen here  - http://ldeveloper.hit.bg/book.load.html&lt;br /&gt;&lt;br /&gt;We will store our chapter names in a JavaScript array:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;var bookchapters = new Array( &quot;chapter1.html&quot;, &quot;chapter2.html&quot;, &quot;chapter3.html&quot; );&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The &lt;span style=&quot;font-weight:bold;&quot;&gt;load&lt;/span&gt; – loads a html and injects it into the DOM element. It can also filter the incoming document – very convenient if you don’t need the whole page. &lt;br /&gt;&lt;br /&gt;So back to our example – the html:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;body  &amp;gt; &lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery  and AJAX  tutorial - part 1&amp;lt;/h1&amp;gt; &lt;br /&gt;  &amp;lt;br  /&amp;gt; &lt;br /&gt;  &amp;lt;br  /&amp;gt; &lt;br /&gt;  &amp;lt;form&amp;gt; &lt;br /&gt;  &amp;lt;input  type=&amp;quot;button&amp;quot; value=&amp;quot;Prev&amp;quot; id=&amp;quot;prev&amp;quot;&amp;gt; &lt;br /&gt;  &amp;lt;input  type=&amp;quot;button&amp;quot; value=&amp;quot;Next&amp;quot; id=&amp;quot;next&amp;quot;&amp;gt; &lt;br /&gt;  &amp;lt;/form&amp;gt; &lt;br /&gt;  &amp;lt;br&amp;gt; &lt;br /&gt;  &amp;lt;br&amp;gt; &lt;br /&gt;  &amp;lt;strong&amp;gt;Book  Title&amp;lt;/strong&amp;gt; &lt;br /&gt;  &amp;lt;div  id=&amp;quot;book&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And we load a chapter with the following(For this example our chapters are in a folder “book”):&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;$(&quot;#book&quot;).load(&quot;book/&quot; + bookchapters[index]);&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The whole code(html, js and css):&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt; &lt;br /&gt;  &amp;lt;head&amp;gt; &lt;br /&gt;  &amp;lt;title&amp;gt;JQuery and AJAX tutorial&amp;lt;/title&amp;gt; &lt;br /&gt;  &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt; &lt;br /&gt; #book { &lt;br /&gt;  background-color: #F0FFF0; &lt;br /&gt;  border : thin ridge; &lt;br /&gt;  height: 450px; &lt;br /&gt;  overflow: scroll &lt;br /&gt;  } &lt;br /&gt; input { &lt;br /&gt;  background-color : White; &lt;br /&gt;  color : #006400;  &lt;br /&gt;  } &lt;br /&gt; &amp;lt;/style&amp;gt; &lt;br /&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; &lt;br /&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt; &lt;br /&gt;  var bookchapters = new Array( &amp;quot;chapter1.html&amp;quot;, &amp;quot;chapter2.html&amp;quot;, &amp;quot;chapter3.html&amp;quot; ); &lt;br /&gt;  $(function () { &lt;br /&gt;  var index = 0; &lt;br /&gt;  $(&amp;quot;#book&amp;quot;).load(&amp;quot;book/&amp;quot; + bookchapters[index]); &lt;br /&gt;  $(&amp;quot;#prev&amp;quot;).click(function () { &lt;br /&gt;  if(index &amp;gt; 0) { &lt;br /&gt;  index--; &lt;br /&gt;  $(&amp;quot;#book&amp;quot;).load(&amp;quot;book/&amp;quot; + bookchapters[index]); &lt;br /&gt;  } &lt;br /&gt;  else { &lt;br /&gt;  alert(&amp;quot;first chapter&amp;quot;); &lt;br /&gt;  } &lt;br /&gt;  }); &lt;br /&gt;  $(&amp;quot;#next&amp;quot;).click(function () { &lt;br /&gt;  if(index &amp;lt; bookchapters.length - 1) { &lt;br /&gt;  index++; &lt;br /&gt;  $(&amp;quot;#book&amp;quot;).load(&amp;quot;book/&amp;quot; + bookchapters[index]); &lt;br /&gt;  } &lt;br /&gt;  else { &lt;br /&gt;  alert(&amp;quot;last chapter&amp;quot;); &lt;br /&gt;  } &lt;br /&gt;  }); &lt;br /&gt; &lt;br /&gt;   &lt;br /&gt;  }); &lt;br /&gt;  &amp;lt;/script&amp;gt; &lt;br /&gt; &amp;lt;/head&amp;gt; &lt;br /&gt;  &amp;lt;body &amp;gt; &lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery and AJAX tutorial - part 1&amp;lt;/h1&amp;gt; &lt;br /&gt;  &amp;lt;br /&amp;gt; &lt;br /&gt;  &amp;lt;br /&amp;gt; &lt;br /&gt;  &amp;lt;form&amp;gt; &lt;br /&gt;  &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Prev&amp;quot; id=&amp;quot;prev&amp;quot;&amp;gt; &lt;br /&gt;  &amp;lt;input type=&amp;quot;button&amp;quot; value=&amp;quot;Next&amp;quot; id=&amp;quot;next&amp;quot;&amp;gt; &lt;br /&gt;  &amp;lt;/form&amp;gt; &lt;br /&gt;  &amp;lt;br&amp;gt; &lt;br /&gt;  &amp;lt;br&amp;gt; &lt;br /&gt;  &amp;lt;strong&amp;gt;Book Title&amp;lt;/strong&amp;gt; &lt;br /&gt;  &amp;lt;div id=&amp;quot;book&amp;quot;&amp;gt; &lt;br /&gt;&amp;lt;/div&amp;gt; &lt;br /&gt;  &amp;lt;/body&amp;gt; &lt;br /&gt;  &amp;lt;/html&amp;gt; &lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Filtering the incoming page&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;This example shows how to use it. The “div:first” after the url in the load parameter string selects only the first div of the incoming document.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt; &amp;lt;html&amp;gt; &lt;br /&gt;  &amp;lt;head&amp;gt; &lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  and AJAX  tutorial&amp;lt;/title&amp;gt; &lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt; &lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt; &lt;br /&gt;   $(function  () { &lt;br /&gt;   $(&amp;quot;#page&amp;quot;).load(&amp;quot;in.html  div:first&amp;quot;);         &lt;br /&gt;   }); &lt;br /&gt;  &amp;lt;/script&amp;gt; &lt;br /&gt;  &amp;lt;/head&amp;gt; &lt;br /&gt;  &amp;lt;body  &amp;gt; &lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery  and AJAX  tutorial - part 1&amp;lt;/h1&amp;gt; &lt;br /&gt;  &amp;lt;br  /&amp;gt; &lt;br /&gt;  &amp;lt;br  /&amp;gt; &lt;br /&gt;  &amp;lt;br&amp;gt; &lt;br /&gt;  &amp;lt;div  id=&amp;quot;page&amp;quot;&amp;gt; &lt;br /&gt;  &amp;lt;/div&amp;gt; &lt;br /&gt;  &amp;lt;/body&amp;gt; &lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And the &lt;span style=&quot;font-weight:bold;&quot;&gt;in.html&lt;/span&gt;:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt; &lt;br /&gt;&amp;lt;body&amp;gt; &lt;br /&gt;&amp;lt;div&amp;gt; &lt;br /&gt;First part of the document that will be loaded! &lt;br /&gt;&amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;br&amp;gt; &lt;br /&gt;&amp;lt;div&amp;gt; &lt;br /&gt;Next part, that won&#39;t show into the other.  &lt;br /&gt;&amp;lt;/div&amp;gt; &lt;br /&gt;&amp;lt;/body&amp;gt; &lt;br /&gt;&amp;lt;/html&amp;gt; &lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKr_edp7gRimna6f_czV92xdMji5iOcklCMUKQ8WsYgNccrcW67fVj15T91r_Z42fdz4Y6bmfJ8rMKY5Bqaw6RwgMc8ytjd-lj21xMWU-gikEA1m68qVfcKda3jkaz7HS96b1Hc4fUMOIi/s1600-h/filter.jpg&quot;&gt;&lt;img style=&quot;cursor:pointer; cursor:hand;width: 320px; height: 66px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKr_edp7gRimna6f_czV92xdMji5iOcklCMUKQ8WsYgNccrcW67fVj15T91r_Z42fdz4Y6bmfJ8rMKY5Bqaw6RwgMc8ytjd-lj21xMWU-gikEA1m68qVfcKda3jkaz7HS96b1Hc4fUMOIi/s320/filter.jpg&quot; border=&quot;1&quot; alt=&quot;&quot;id=&quot;BLOGGER_PHOTO_ID_5268113638492353138&quot; /&gt;&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2008/11/simple-ajax-with-jquerypart-1-ugly.html</link><author>noreply@blogger.com (Web)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKr_edp7gRimna6f_czV92xdMji5iOcklCMUKQ8WsYgNccrcW67fVj15T91r_Z42fdz4Y6bmfJ8rMKY5Bqaw6RwgMc8ytjd-lj21xMWU-gikEA1m68qVfcKda3jkaz7HS96b1Hc4fUMOIi/s72-c/filter.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-103225241713641688</guid><pubDate>Thu, 06 Nov 2008 11:50:00 +0000</pubDate><atom:updated>2008-11-06T04:15:58.308-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">examples</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><category domain="http://www.blogger.com/atom/ns#">Web 2.0</category><title>Intro to JQuery - part 2 - JQuery examples</title><description>If this is your first encounter of JQuery, I recommend the post – &lt;a href=&quot;http://ldeveloper.blogspot.com/2008/10/intro-to-jquery-basic-tutorial.html&quot;&gt;Intro to JQuery&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;This is a short document on how-to use JQuery API. Necessary knowledge for this post includes JavaScript, HTML and CSS basics.  &lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let’s change the last example of the previous post a little. We can handle the logic without the counter variable:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;#ourID&amp;quot;).click(function  () {&lt;br /&gt;  var c =  parseInt($(this).html());&lt;br /&gt;  $(this).html(c  + 1);&lt;br /&gt;  });&lt;br /&gt;  } );&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;We can add more complex code with the html(), not only one number. For example:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;#ourID&amp;quot;).click(function  () {&lt;br /&gt;  $(this).html(String($(this).html() +  &amp;quot;&amp;lt;br/&amp;gt;&amp;lt;b&amp;gt;We added a row!&amp;lt;/b&amp;gt;&amp;quot;));&lt;br /&gt;  });&lt;br /&gt;  } );&lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery  basic tutorial&amp;lt;/h1&amp;gt;&lt;br /&gt;  Click in  the box:&lt;br /&gt;  &amp;lt;div  id=&amp;quot;ourID&amp;quot; style=&amp;quot;font-size: larger;background-color:  #FFA500;border : medium dashed;text-align: center; width: 250px&amp;quot;&amp;gt;&lt;br /&gt;  This is our  test div element.&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Be careful to add a correct html for the html() function value or you will end with unexpected results. &lt;br /&gt;&lt;br /&gt;JQuery have more methods for DOM manipulations. For full list of these methods I recommend reading the documentation - &lt;a href=&quot;http://docs.jquery.com/Manipulation&quot;&gt;http://docs.jquery.com/Manipulation&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Very power JQuery functionality is the opportunity to easily traverse the DOM tree. One very useful element in this part is the each(). It is used to execute a function within the context of every matched element. This is simple example of its usage:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;div&amp;quot;).each(function  () {&lt;br /&gt;  $(this).css({border :  &amp;quot;medium double Red&amp;quot;, backgroundColor: &amp;quot;orange&amp;quot;});&lt;br /&gt;  }&lt;br /&gt;  );&lt;br /&gt;  } );&lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery  basic tutorial&amp;lt;/h1&amp;gt;&lt;br /&gt;  &amp;lt;div&amp;gt;First  div element&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;div&amp;gt;Second  div element&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And now a little more complex example:&lt;br /&gt;The code bellow gets all the &amp;lt;p&amp;gt;(paragraph) childs of the &amp;lt;div&amp;gt; elements and sets them a css class “our class”. There are many other ways to achieve the same thing, this is just example of using each() and children().&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;style  type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;  .ourclass {&lt;br /&gt;  border : medium double #FFA500;&lt;br /&gt;  width: 90px;&lt;br /&gt;  height: 90px;&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt; &amp;lt;/style&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;div  &amp;quot;).each(function () {&lt;br /&gt;  $(this).children(&amp;quot;p&amp;quot;).each(function  () {&lt;br /&gt;  $(this).addClass(&amp;quot;ourclass&amp;quot;);&lt;br /&gt;  });&lt;br /&gt;  }&lt;br /&gt;  );&lt;br /&gt;  } );&lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery  basic tutorial&amp;lt;/h1&amp;gt;&lt;br /&gt;  &amp;lt;div  style=&amp;quot;border : 1px solid Black;&amp;quot;&amp;gt;First div  element&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/div&amp;gt;&amp;lt;br/&amp;gt;&lt;br /&gt;  &amp;lt;div  style=&amp;quot;border : 1px solid Black;&amp;quot;&amp;gt;Second div element with two  paragraphs&lt;br /&gt;  &amp;lt;p&amp;gt;First  &amp;lt;b&amp;gt;p&amp;lt;/b&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;  &amp;lt;p&amp;gt;Second  p&amp;lt;/p&amp;gt;&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;p  style=&amp;quot;border : 1px dotted Black;&amp;quot;&amp;gt;This is a paragraph but it is  not a div child&amp;lt;/p&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;/div&gt;</description><link>http://ldeveloper.blogspot.com/2008/11/intro-to-jquery-part-2-jquery-examples.html</link><author>noreply@blogger.com (Web)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-2414039472638785375</guid><pubDate>Fri, 31 Oct 2008 17:45:00 +0000</pubDate><atom:updated>2008-11-01T08:33:33.708-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">jquery</category><title>Intro to JQuery</title><description>JQuery is a lightweight JavaScript framework that got a lot of attention lately so I decided to write few rows about it.  &lt;br /&gt;&lt;br /&gt;This post-tutorial is recommended for people with basic javascript, html and css knowledge.&lt;br /&gt;&lt;br /&gt;To run and test the examples in this tutorial, you need to save them as html pages. You can use any text editor like notepad or anything convenient. &lt;br /&gt;&lt;br /&gt;What do you need to start using JQuery? Just download and save it in the same directory (I’ll call it jquery.js) and include the following code anywhere above your javascript code:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The best place for our javascript code is in the head section of the html document but you are not restricted to it. Anyway I’ll use the head section for most of my examples.&lt;br /&gt;&lt;br /&gt;Ok, let’s use some basic functionality to test if we’ve done it right. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;example1.html&lt;/span&gt;:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot;  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(document).ready(function  () {&lt;br /&gt;  alert(&#39;Works!!!&#39;);&lt;br /&gt;  } );&lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  JQuery basic tutorial&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;So, what happens here? Nothing special, we just show an alert with text ‘Works!!!’. &lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight:bold;&quot;&gt;$ function&lt;/span&gt; is a factory method (shortcut) for the JQuery object. &lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;$(document).ready(function() {&lt;br /&gt; // code&lt;br /&gt;});&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;With &lt;span style=&quot;font-weight:bold;&quot;&gt;$(document).ready&lt;/span&gt; we register our code to the ready event of the document. The above code can be shortened:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;$(function () {&lt;br /&gt; // code&lt;br /&gt;} );&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Selectors and events&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;In JQuery an element can be selected in different ways – by id, by element type, by css class and so on. &lt;br /&gt;This is a simple code showing how to use events and selectors:&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot;  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;#ourID&amp;quot;).click(function  () {&lt;br /&gt;  alert(&amp;quot;Click&amp;quot;);&lt;br /&gt;  });&lt;br /&gt;  } );&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery basic tutorial&amp;lt;/h1&amp;gt;&lt;br /&gt;  &amp;lt;div id=&amp;quot;ourID&amp;quot;  style=&amp;quot;font-size: larger;background-color: #FFA500;border : medium  dashed;text-align: center; width: 250px&amp;quot;&amp;gt;&lt;br /&gt;  Div&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The click(fn) binds a function to the click event of our matched element.&lt;br /&gt;Let’s make our example a little more complex. We will count the clicks.&lt;br /&gt;&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;html&amp;gt;&lt;br /&gt;  &amp;lt;head&amp;gt;&lt;br /&gt;  &amp;lt;title&amp;gt;JQuery  basic tutorial&amp;lt;/title&amp;gt;&lt;br /&gt;  &amp;lt;script type=&amp;quot;text/javascript&amp;quot;  src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;script  type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;  var counter = 0;&lt;br /&gt;  $(function  () {&lt;br /&gt;  $(&amp;quot;#ourID&amp;quot;).click(function  () {&lt;br /&gt;  counter++;&lt;br /&gt;  $(this).html(counter);&lt;br /&gt;  });&lt;br /&gt;  } );&lt;br /&gt;  &lt;br /&gt;  &amp;lt;/script&amp;gt;&lt;br /&gt;  &amp;lt;/head&amp;gt;&lt;br /&gt;  &amp;lt;body&amp;gt;&lt;br /&gt;  &amp;lt;h1&amp;gt;JQuery basic tutorial&amp;lt;/h1&amp;gt;&lt;br /&gt;  Click in the box:&lt;br /&gt;  &amp;lt;div id=&amp;quot;ourID&amp;quot;  style=&amp;quot;font-size: larger;background-color: #FFA500;border : medium  dashed;text-align: center; width: 250px&amp;quot;&amp;gt;&lt;br /&gt;  0&lt;br /&gt;  &amp;lt;/div&amp;gt;&lt;br /&gt;  &amp;lt;/body&amp;gt;&lt;br /&gt;  &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;</description><link>http://ldeveloper.blogspot.com/2008/10/intro-to-jquery-basic-tutorial.html</link><author>noreply@blogger.com (Web)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-5114368633381389827</guid><pubDate>Tue, 28 Oct 2008 23:36:00 +0000</pubDate><atom:updated>2008-10-28T18:11:27.731-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Fast and easy Hibernate example-tutorial (Part 2)</title><description>&lt;a href=&quot;http://ldeveloper.blogspot.com/2008/10/fast-and-easy-hibernate-example.html&quot;&gt;Fast and easy Hibernate example-tutorial (Part 1)&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In the first part of this tutorial we met the basic functionality of Hibernate. We store and retrieve some simple objects to and from the database.&lt;br /&gt;&lt;br /&gt;This time I’ll make the example a little harder. Now our table books will have author_id instead of author(simple string for the name) and we will have table authors with two columns: id, name.&lt;br /&gt;&lt;br /&gt;Let’s assume that our book can have single author but our authors may have many books. It is rather dull example, far away from the real world where one book may be written by more than ten people but it would be easy for my example this way.&lt;br /&gt;&lt;br /&gt;Also I&#39;ll make the id keys serial - I don&#39;t want to bother to set ids.&lt;br /&gt;&lt;br /&gt;Here is the Author class:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;public class Author {&lt;br /&gt; private Integer id;&lt;br /&gt; private String name;&lt;br /&gt;&lt;br /&gt; public Integer getId() {&lt;br /&gt;  return id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getName() {&lt;br /&gt;  return name;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setId(Integer id) {&lt;br /&gt;  this.id = id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setName(String name) {&lt;br /&gt;  this.name = name;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And the Author.hbm.xml mapping:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;&lt;br /&gt; &amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;&lt;br /&gt; &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;&lt;br /&gt;&lt;br /&gt; &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&amp;gt;&lt;br /&gt; &amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt; &amp;lt;class name=&quot;Author&quot; table=&quot;authors&quot;&amp;gt;&lt;br /&gt;&lt;span style=&quot;color: #FF8000;&quot;&gt;&lt;br /&gt; &amp;lt;id name=&quot;id&quot; type=&quot;java.lang.Integer&quot; column=&quot;id&quot;&amp;gt;&lt;br /&gt; &amp;lt;generator class=&quot;sequence&quot;&amp;gt;&lt;br /&gt; &amp;lt;param name=&quot;sequence&quot;&amp;gt;authors_id_seq&amp;lt;/param&amp;gt;&lt;br /&gt; &amp;lt;/generator&amp;gt;&lt;br /&gt; &amp;lt;/id&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;property name=&quot;name&quot; column=&quot;name&quot; type=&quot;java.lang.String&quot; /&amp;gt; &lt;br /&gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Book.java:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;public class Book {&lt;br /&gt; private Integer id;&lt;br /&gt; private String title;&lt;br /&gt; private Author author;&lt;br /&gt;&lt;br /&gt; public Integer getId() {&lt;br /&gt;  return id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public String getTitle() {&lt;br /&gt;  return title;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public Author getAuthor() {&lt;br /&gt;  return author;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setId(Integer id) {&lt;br /&gt;  this.id = id;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setTitle(String title) {&lt;br /&gt;  this.title = title;&lt;br /&gt; }&lt;br /&gt;&lt;br /&gt; public void setAuthor(Author author) {&lt;br /&gt;  this.author = author;&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;Book.hbm.xml:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;  &amp;quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&amp;quot;&lt;br /&gt;  &amp;quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt; &amp;lt;class name=&amp;quot;Book&amp;quot; table=&amp;quot;books&amp;quot;&amp;gt;&lt;br /&gt; &amp;lt;id name=&amp;quot;id&amp;quot; type=&amp;quot;java.lang.Integer&amp;quot; column=&amp;quot;id&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;generator class=&amp;quot;sequence&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;param name=&amp;quot;sequence&amp;quot;&amp;gt;books_id_seq&amp;lt;/param&amp;gt;&lt;br /&gt;&lt;br /&gt;  &amp;lt;/generator&amp;gt;&lt;br /&gt;  &amp;lt;/id&amp;gt;&lt;br /&gt; &amp;lt;property name=&amp;quot;title&amp;quot; column=&amp;quot;title&amp;quot; type=&amp;quot;java.lang.String&amp;quot; /&amp;gt;&lt;br /&gt;&lt;span style=&quot;color: #FF8000;&quot;&gt;&lt;br /&gt; &amp;lt;many-to-one name=&amp;quot;author&amp;quot; class=&amp;quot;Author&amp;quot; lazy=&amp;quot;false&amp;quot;&amp;gt;&lt;br /&gt;  &amp;lt;column name=&amp;quot;author_id&amp;quot;&amp;gt;&amp;lt;/column&amp;gt; &lt;br /&gt;  &amp;lt;/many-to-one&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&amp;lt;/class&amp;gt;&lt;br /&gt;&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And finally the hibernate.cfg.xml:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;&amp;lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br /&gt;&amp;quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&amp;quot;&lt;br /&gt;&amp;quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&amp;quot;&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;hibernate-configuration&amp;gt;&lt;br /&gt;&amp;lt;session-factory&amp;gt;&lt;br /&gt;&amp;lt;property name=&amp;quot;hibernate.dialect&amp;quot;&amp;gt;org.hibernate.dialect.PostgreSQLDialect&amp;lt;/property&amp;gt;&lt;br /&gt;  &amp;lt;property name=&amp;quot;hibernate.connection.driver_class&amp;quot;&amp;gt;org.postgresql.Driver&amp;lt;/property&amp;gt;&lt;br /&gt;  &amp;lt;property name=&amp;quot;hibernate.connection.url&amp;quot;&amp;gt;jdbc:postgresql://localhost/example&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;property name=&amp;quot;hibernate.connection.username&amp;quot;&amp;gt;username&amp;lt;/property&amp;gt;&lt;br /&gt;  &amp;lt;property name=&amp;quot;hibernate.connection.password&amp;quot;&amp;gt;secret&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;property name=&amp;quot;cache.provider_class&amp;quot;&amp;gt;org.hibernate.cache.NoCacheProvider&amp;lt;/property&amp;gt;&lt;br /&gt;  &amp;lt;property name=&amp;quot;connection.pool_size&amp;quot;&amp;gt;1&amp;lt;/property&amp;gt;&lt;br /&gt;&amp;lt;property name=&amp;quot;show_sql&amp;quot;&amp;gt;true&amp;lt;/property&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;mapping resource=&amp;quot;Author.hbm.xml&amp;quot; /&amp;gt;&lt;br /&gt;  &amp;lt;mapping resource=&amp;quot;Book.hbm.xml&amp;quot; /&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/session-factory&amp;gt;&lt;br /&gt;  &amp;lt;/hibernate-configuration&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;We have our classes and now we are ready to test them. This is a simple test example for storing objects:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import org.hibernate.Criteria;&lt;br /&gt;import org.hibernate.Session;&lt;br /&gt;import org.hibernate.SessionFactory;&lt;br /&gt;import org.hibernate.Transaction;&lt;br /&gt;import org.hibernate.cfg.Configuration;&lt;br /&gt;&lt;br /&gt;public class BookExample {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;  Session session = sessionFactory.openSession();&lt;br /&gt;  &lt;br /&gt;  Author author = new Author();&lt;br /&gt;  author.setName(&quot;Crazy book author First&quot;);&lt;br /&gt;  Author author2 = new Author();&lt;br /&gt;  author2.setName(&quot;Writer&quot;);&lt;br /&gt;  Book book = new Book();&lt;br /&gt;  book.setTitle(&quot;Crazy book&quot;);&lt;br /&gt;  book.setAuthor(author);&lt;br /&gt;  Book book2 = new Book();&lt;br /&gt;  book2.setTitle(&quot;Crazy old book&quot;);&lt;br /&gt;  book2.setAuthor(author);&lt;br /&gt;  Book book3 = new Book();&lt;br /&gt;  book3.setTitle(&quot;Book Title&quot;);&lt;br /&gt;  book3.setAuthor(author2);&lt;br /&gt;  &lt;br /&gt;  Transaction tx = session.beginTransaction();&lt;br /&gt;  session.save(author);&lt;br /&gt;  session.save(author2);&lt;br /&gt;  session.save(book);&lt;br /&gt;  session.save(book2);&lt;br /&gt;  session.save(book3);&lt;br /&gt;&lt;br /&gt;  tx.commit();&lt;br /&gt;  &lt;br /&gt;  session.close();&lt;br /&gt;  sessionFactory.close();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;The result must be something like this:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Blue;font-family: &quot;Courier New&quot;, Courier, monospace;font-size: smaller;&quot;&gt;Hibernate: select nextval (&#39;authors_id_seq&#39;)&lt;br /&gt;Hibernate: select nextval (&#39;authors_id_seq&#39;)&lt;br /&gt;Hibernate: select nextval (&#39;books_id_seq&#39;)&lt;br /&gt;Hibernate: select nextval (&#39;books_id_seq&#39;)&lt;br /&gt;Hibernate: select nextval (&#39;books_id_seq&#39;)&lt;br /&gt;Hibernate: insert into authors (name, id) values (?, ?)&lt;br /&gt;Hibernate: insert into authors (name, id) values (?, ?)&lt;br /&gt;Hibernate: insert into books (title, author_id, id) values (?, ?, ?)&lt;br /&gt;Hibernate: insert into books (title, author_id, id) values (?, ?, ?)&lt;br /&gt;Hibernate: insert into books (title, author_id, id) values (?, ?, ?)&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;And now to retrieve the objects from the database:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;import java.util.Iterator;&lt;br /&gt;import java.util.List;&lt;br /&gt;&lt;br /&gt;import org.hibernate.Criteria;&lt;br /&gt;import org.hibernate.Session;&lt;br /&gt;import org.hibernate.SessionFactory;&lt;br /&gt;import org.hibernate.Transaction;&lt;br /&gt;import org.hibernate.cfg.Configuration;&lt;br /&gt;&lt;br /&gt;public class BookExample2 {&lt;br /&gt; public static void main(String[] args) {&lt;br /&gt;  SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;  Session session = sessionFactory.openSession();&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;  Criteria criteria = session.createCriteria(Book.class);&lt;br /&gt;  List books = criteria.list();&lt;br /&gt;&lt;br /&gt;  Iterator it = books.iterator();&lt;br /&gt;  while (it.hasNext()) {&lt;br /&gt;   Book book = (Book) it.next();&lt;br /&gt;   System.out.println(&quot;Book: &quot; + book.getTitle() + &quot; with author: &quot; + book.getAuthor().getName());&lt;br /&gt;  }&lt;br /&gt;&lt;br /&gt;  session.close();&lt;br /&gt;  sessionFactory.close();&lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;The result:&lt;br /&gt;&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Blue;font-family: &quot;Courier New&quot;, Courier, monospace;font-size: smaller;&quot;&gt;Hibernate: select this_.id as id1_0_, this_.title as title1_0_, this_.author_id as author3_1_0_ from books this_&lt;br /&gt;Hibernate: select author0_.id as id0_0_, author0_.name as name0_0_ from authors author0_ where author0_.id=?&lt;br /&gt;Hibernate: select author0_.id as id0_0_, author0_.name as name0_0_ from authors author0_ where author0_.id=?&lt;br /&gt;Book: Crazy book with author: Crazy book author First&lt;br /&gt;Book: Book Title with author: Writer&lt;br /&gt;Book: Crazy old book with author: Crazy book author First&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;In this example I use few rather interesting options. The first is the generator child element of id with option sequence. It uses a sequence from our database (PostgreSQL, remember? ). &lt;br /&gt;The second is many-to-one relation between the objects with lazy set to false. This option tells Hibernate to retrieve the author object together with our book object. However, most of the time you will use lazy set to true, this is also the default value.</description><link>http://ldeveloper.blogspot.com/2008/10/fast-and-easy-hibernate-example_28.html</link><author>noreply@blogger.com (Web)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-7457564770435962471</guid><pubDate>Fri, 17 Oct 2008 19:35:00 +0000</pubDate><atom:updated>2009-11-16T01:30:18.273-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Database</category><category domain="http://www.blogger.com/atom/ns#">Hibernate</category><category domain="http://www.blogger.com/atom/ns#">Java</category><title>Fast and easy Hibernate example-tutorial (Part 1)</title><description>This tutorial tries to provide fast and easy instructions on getting started with Hibernate. You can download Hibernate from &lt;a href=&quot;http://www.hibernate.org/&quot;&gt;http://www.hibernate.org&lt;/a&gt;.&lt;br /&gt;
&lt;span style=&quot;font-style: italic;font-size:85%;&quot; &gt;I won&#39;t explain how to make Java project with eclipse or netbeans, it is beyond the scope of this text. &lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Hibernate is an open-source ORM(object relational mapping) library. It is one of the basic tools for fast and reliable java application development. Hibernate is published under LGPL license that allows you to use it in both open-source and commercial projects.&lt;br /&gt;
&lt;br /&gt;
The fastest way to learn something new is with examples. So I&#39;ll write some basic example for its usage. For this exercise I&#39;ll use &lt;a href=&quot;http://www.postgresql.org/&quot;&gt;PostgreSQL&lt;/a&gt; as my database server. It doesn&#39;t matter so much, changing to another type is easy from the Hibernate configuration file.&lt;br /&gt;
&lt;br /&gt;
Lets have database called &#39;example&#39; with table &#39;books&#39;. Books will have 3 columns - id, title and author.&lt;br /&gt;
Here is our persistent class - I&#39;ll call it Book&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;
public class Book {&lt;br /&gt;
private Integer id;&lt;br /&gt;
&lt;br /&gt;
private String title;&lt;br /&gt;
&lt;br /&gt;
private String author;&lt;br /&gt;
&lt;br /&gt;
public String getAuthor() {&lt;br /&gt;
return author;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setAuthor(String author) {&lt;br /&gt;
this.author = author;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Integer getId() {&lt;br /&gt;
return id;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setId(Integer id) {&lt;br /&gt;
this.id = id;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public String getTitle() {&lt;br /&gt;
return title;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void setTitle(String title) {&lt;br /&gt;
this.title = title;&lt;br /&gt;
} &lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
And this would be our mapping xml file &lt;span style=&quot;font-weight: bold;&quot;&gt;Book.hbm.xml&lt;/span&gt;:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;
&amp;lt;?xml version=&quot;1.0&quot;?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!DOCTYPE hibernate-mapping PUBLIC&lt;br /&gt;
&lt;br /&gt;
&quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;&lt;br /&gt;
&lt;br /&gt;
&quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&amp;gt;&lt;p&gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;lt;hibernate-mapping&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;class name=&quot;Book&quot; table=&quot;books&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;id name=&quot;id&quot; column=&quot;id&quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;generator class=&quot;native&quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/id&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;title&quot; column=&quot;title&quot; type=&quot;java.lang.String&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;author&quot; column=&quot;author&quot; type=&quot;java.lang.String&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/class&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-mapping&amp;gt;&lt;br /&gt;
&lt;/p&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
This is the Hibernate configuration file :&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;
&lt;p&gt;&amp;lt;!DOCTYPE hibernate-configuration PUBLIC&lt;br /&gt;
&lt;br /&gt;
&quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;&lt;br /&gt;
&lt;br /&gt;
&quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&amp;gt;&lt;/p&gt;&lt;br /&gt;
&lt;p&gt;&amp;lt;hibernate-configuration&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;session-factory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;hibernate.dialect&quot;&amp;gt;org.hibernate.dialect.PostgreSQLDialect&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;hibernate.connection.driver_class&quot;&amp;gt;org.postgresql.Driver&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;hibernate.connection.url&quot;&amp;gt;jdbc:postgresql://localhost/example&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;hibernate.connection.username&quot;&amp;gt;username&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;hibernate.connection.password&quot;&amp;gt;secret&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;connection.pool_size&quot;&amp;gt;1&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;property name=&quot;show_sql&quot;&amp;gt;true&amp;lt;/property&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;mapping resource=&quot;Book.hbm.xml&quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/session-factory&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/hibernate-configuration&amp;gt;&lt;/p&gt;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Now we are ready to test what we&#39;ve done. Lets make simple text class BookExercise.&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;
import org.hibernate.Session;&lt;br /&gt;
import org.hibernate.SessionFactory;&lt;br /&gt;
import org.hibernate.Transaction;&lt;br /&gt;
import org.hibernate.cfg.Configuration;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class BookExercise {&lt;br /&gt;
public static void main(String[] args) {&lt;br /&gt;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;
Session session = sessionFactory.openSession();&lt;br /&gt;
&lt;br /&gt;
Book firstBook = new Book();&lt;br /&gt;
firstBook.setId(1);&lt;br /&gt;
firstBook.setTitle(&quot;Our first book title&quot;);&lt;br /&gt;
firstBook.setAuthor(&quot;Our Author&quot;);&lt;br /&gt;
&lt;br /&gt;
Book secondBook = new Book();&lt;br /&gt;
secondBook.setId(2);&lt;br /&gt;
secondBook.setTitle(&quot;Second book title&quot;);&lt;br /&gt;
secondBook.setAuthor(&quot;Our Author&quot;);&lt;br /&gt;
&lt;br /&gt;
Transaction tx = session.beginTransaction();&lt;br /&gt;
&lt;br /&gt;
session.saveOrUpdate(firstBook);&lt;br /&gt;
session.saveOrUpdate(secondBook);&lt;br /&gt;
&lt;br /&gt;
tx.commit();&lt;br /&gt;
&lt;br /&gt;
session.close();&lt;br /&gt;
sessionFactory.close();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Now you must have two records in your books table. To view them you can try to change the exercise class this way:&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: medium groove ; background-color: rgb(250, 240, 230); color: Black;&quot;&gt;&lt;br /&gt;
import java.util.Iterator;&lt;br /&gt;
import java.util.List;&lt;br /&gt;
&lt;br /&gt;
import org.hibernate.Criteria;&lt;br /&gt;
import org.hibernate.Session;&lt;br /&gt;
import org.hibernate.SessionFactory;&lt;br /&gt;
import org.hibernate.cfg.Configuration;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
public class BookExercise {&lt;br /&gt;
public static void main(String[] args) {&lt;br /&gt;
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();&lt;br /&gt;
Session session = sessionFactory.openSession();&lt;br /&gt;
&lt;br /&gt;
Criteria criteria = session.createCriteria(Book.class);&lt;br /&gt;
List books = criteria.list();&lt;br /&gt;
&lt;br /&gt;
Iterator it = books.iterator();&lt;br /&gt;
while(it.hasNext()) {&lt;br /&gt;
Book book = (Book) it.next();&lt;br /&gt;
System.out.println(&quot;Book: &quot; + book.getTitle() + &quot; with author: &quot; + book.getAuthor());&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
session.close();&lt;br /&gt;
sessionFactory.close();&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;</description><link>http://ldeveloper.blogspot.com/2008/10/fast-and-easy-hibernate-example.html</link><author>noreply@blogger.com (Web)</author><thr:total>10</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-850196223709167114</guid><pubDate>Thu, 16 Oct 2008 20:13:00 +0000</pubDate><atom:updated>2008-10-16T13:14:40.815-07:00</atom:updated><title>Laziness</title><description>I haven’t written anything to my blog for a while. I am not exactly devoted blogger, so this is easy to explain. And recently I am too lazy to do anything. Or maybe I am just tired.</description><link>http://ldeveloper.blogspot.com/2008/10/laziness.html</link><author>noreply@blogger.com (Web)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6010256189300350666.post-3647902122683699732</guid><pubDate>Mon, 05 May 2008 01:18:00 +0000</pubDate><atom:updated>2008-05-04T18:26:32.914-07:00</atom:updated><title>Offtopic: A picture of the sky</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_fbksA0xlZwZ_SbLw7bgfdCMpPedGR_tD6myHrbLFpV9CCr1C0MtZGPLTM94uHXSlSsp_hIOdZRzg_WV9sjuiIVInT6OTdO0hTyPvl54qd6MxaSszX8ljUPudWnexynqD_naPSBiqkA/s1600-h/sky.jpg&quot;&gt;&lt;img style=&quot;cursor: pointer;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_fbksA0xlZwZ_SbLw7bgfdCMpPedGR_tD6myHrbLFpV9CCr1C0MtZGPLTM94uHXSlSsp_hIOdZRzg_WV9sjuiIVInT6OTdO0hTyPvl54qd6MxaSszX8ljUPudWnexynqD_naPSBiqkA/s400/sky.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5196699023385391602&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;</description><link>http://ldeveloper.blogspot.com/2008/05/offtopic-picture-of-sky.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_fbksA0xlZwZ_SbLw7bgfdCMpPedGR_tD6myHrbLFpV9CCr1C0MtZGPLTM94uHXSlSsp_hIOdZRzg_WV9sjuiIVInT6OTdO0hTyPvl54qd6MxaSszX8ljUPudWnexynqD_naPSBiqkA/s72-c/sky.jpg" height="72" width="72"/><thr:total>0</thr:total></item></channel></rss>