Recent Notes
Displaying keyword search results 81 - 90
Created by James on September 03, 2010 20:43:28
Last update: September 03, 2010 20:43:48
Match a regex:
'Free online videos for $.10 each'.match(/each$/);...
Search for a regex pattern:
'Jack Jake Jason'.search(/son/);
// 12
Replace by regex match:
'Jack Jake Jason'.replace(/.a/g, 'Ma');
// Mack...
Split by regex:
'She sells seashells by the seashore'.split(/\s/);...
Created by James on September 03, 2010 15:34:30
Last update: September 03, 2010 15:34:43
Combine the elements of a JavaScript array to a string by the join method:
a = [ 'Eeny', 'meeny', 'miny', 'moe' ];
a.join(...
Created by James on September 03, 2010 15:28:59
Last update: September 03, 2010 15:28:59
For a JavaScript array, the push method appends an element to the end, the unshift method inserts an element to the beginning.
The following code yields the array [1, 2, 3, 4] :
a = [];
a.push(3);
a.push(4);
a.unshift(2...
Created by Fang on March 23, 2010 03:50:11
Last update: August 18, 2010 21:59:52
This is a simple web application with a single servlet and a single JSP page. It is intended to be a test bed for JSTL tags. You may want to store all syntax, rules, and exceptions in your head, but in my opinion nothing beats a simple test program that allows you play with it all you want. So here it is (build with Maven ). Prerequisites: Maven: http://maven.apache.org/ . You don't need any prior knowledge of Maven, but you need to install the binary. JBoss: http://jboss.org/jbossas/downloads/ , or Tomcat: http://tomcat.apache.org/ if you don't run the SQL tests. You need to know how to deploy a web application (shh! Don't tell your boss it's just copying a file to the deployment folder). Steps: The directory...
Created by James on June 30, 2010 19:04:45
Last update: July 03, 2010 21:24:33
Technically, file upload cannot be handled by Ajax, because XMLHttpRequest (XHR) does not handle file inputs. All techniques not using Flash rely on an invisible iframe as the upload form submit target. JavaScript then grabs the response content from the iframe and present it, giving the same illusion as Ajax. webtoolkit AIM The technique by webtoolkit is very simple. It involves 3 simple steps: include the AIM script, implement the start/finish JavaScript functions, and add an onsubmit handler to the normal file upload form. The hooked up form looks like:
<head> <script type="text/javascript" src="webt... The AIM script is also quite simple: /** * * AJAX IFRAME METHOD (AIM) * http... The above code only supports HTML responses. In order to support JSON responses, the above...
Created by James on June 30, 2010 20:14:28
Last update: July 03, 2010 18:41:12
The HTML page
<!DOCTYPE html>
<html>
<head>
<title>jQu...
Client Side Code
// called before upload submit
function sta...
Server Side Code
Using Apache Commons FileUpload as example.
Upload code (responds to fileUpload.do ):
final HttpSession session = httpServletRequest...
Progress code (responds to uploadProgress.do ):
HttpSession session = httpServletRequest.getSe...
Created by James on June 24, 2010 22:04:19
Last update: June 24, 2010 22:04:19
Start with this page:
<!DOCTYPE html>
<html>
<head>
<title>jQu...
When you click "Submit", the form submits fine.
Now turn the form to a jQuery dialog:
<head>
<title>jQuery UI Dialog</title>
...
When you click "Submit", the form no longer submits!
Why? When you convert the contents of the form into a dialog, the form becomes empty! The "Submit" button is no longer associated with the form.
Conclusion: you should always put the form tag inside the element you are converting to a dialog.
Created by James on June 22, 2010 19:40:53
Last update: June 22, 2010 19:52:53
Use jQuery to submit a form by clicking a button not associated with the form. The jQuery submit method can also be used to associate an event handler on the form.
<!DOCTYPE html>
<html>
<head>
<title>jQu...
To submit the first form on the page:
$('form:first').submit();
Created by Fang on April 01, 2010 22:24:58
Last update: April 02, 2010 02:49:38
In this note I'll show you how to create and package a JSP custom tag. The purpose of this tag is to display a random splash image for a home page, among a set of images. We should be able to add or delete candidate splash images from the WAR archive without the need to change the JSP. This is the intended use of the tag:
<%@ taglib uri="http://custom.tag.com/demo" prefix... In the above example you provide a set of images named splash*.png (e.g., splash1.png, spalsh2.png, ...), and the tag will pick a random one to display when the JSP is rendered. Let's get started. I'll use Maven for this purpose. Create the standard Maven directory structure ./pom.xml ./src ./src/main ./src/main/jav... pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0"... SplashTag.java package tagdemo; import java.util.ArrayList......
Created by James on March 16, 2010 16:55:51
Last update: March 16, 2010 19:29:28
I had this seemingly innocent code that did not work:
<html>
<body>
<script language="JavaScript"...
I fired up the Chrome JavaScript console and it told me that:
Uncaught TypeError: object is not a function .
When the name sameAsInputName appeared in the inline event handler, the browser thinks that it refers to the input field(s), not the JavaScript function!
It works as expected if you attach the event handler later:
<html>
<body>
<script language="JavaScript"...