AJAX Example code showing XML response in a DIV tag

Here is the example code which demonstrates how we can show the response from a XML file to the DIV tag. 
 
Contents of MyPage.html are like below.
 


Using responseText with innerHTML
 

 

   

                        onclick="startRequest();"/>
   

   


 
Notice the line in Javascript.
 
document.getElementById("results").innerHTML = xmlHttp.responseText;
 
 This is doing all the magic for you.
 
Contents of reponse.xml
 

   
       
           
           
           
       
       
           
           
           
       
       
           
           
           
       
       
           
           
           
       
   
My NameLocationAge
JohnNH20
PeterCA25
HaryNC33
 
Keep both the files in the same directory on server and run it.
 


AJAX Example code, AJAX response in DIV, AJAX showing response in DIV, USe AJAX to populate DIV, AJAX XML response, display AJAX result in DIV

What are the status values you need to deal with when working with AJAX

The XMLHttpRequest object has few properties
 
onreadystatechange: The event handler that fires at every state change, typically a call to a JavaScript function.
 
readyState: The state of the request. The five possible values are 0 = uninitialized, 1 = loading, 2 = loaded, 3 = interactive, and 4 = complete.
 
responseText: The response from the server as a string.
 
responseXML: The response from the server as XML. This object can be parsed and examined as a DOM object.
 
status: The HTTP status code from the server (that is, 200 for OK, 404 for Not Found, and so on).
 
statusText: The text version of the HTTP status code (that is, OK or Not Found, and so on).
 
 
Here is a example code which demonstrates how these atributes can be used
 
 
function doSomething() {
 //..do something here, like adding parameter values etc...
 xmlHttp.open("GET", url);
 xmlHttp.onreadystatechange = callback;
 xmlHttp.send(null);
}
function callback() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
        //do you required work here
    }
  }
}
 
Notice the line 
xmlHttp.onreadystatechange = callback;
 
in doSomething method which is assigning a value as "callback" to the onreadystatechange attribute. 
The value is name of a method which called every time readystate of XMLHttpRequest object is changed.
 



AJAX request status, AJAX code example, AJAX code for checking status values of http request object, AJAX programming check of http request, working with request status in AJAX

How to Create an Instance of the XMLHttpRequest Object - AJAX

XMLHttpRequest is backbone of AJAX framework. We have to first create an XMLHttpRequest object using JavaScript before we can use the object to send request. You can use JavaScript in a couple of ways to create an instance of XMLHttpRequest. Internet Explorer implements XMLHttpRequest as an ActiveX object, and other browsers such as Firefox, Safari, and Opera implement it as a native JavaScript object. Because of these differences, the JavaScript code must contain logic to create an instance of XMLHttpRequest using the ActiveX technique or using the native JavaScript object technique.
 
var xmlHttp;
 
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}

Struts 1 vs Struts 2

Here are few comparison of Jakarta Struts framework version 1.X and 2.X
The entire approach has been changed in Struts 2 by introduction of dependency injection and interceptors. Here are few key differences...


1. Servlet Dependency:


Actions in Struts1 have dependencies on the servlet API since the HttpServletRequest and HttpServletResponse objects are passed to the execute method when an Action is invoked.

In case of Struts 2, Actions are not container dependent because they are made simple POJOs. In struts 2, the servlet contexts are represented as simple Maps which allows actions to be tested in isolation. Struts 2 Actions can access the original request and response, if required. However, other architectural elements reduce or eliminate the need to access the HttpServetRequest or HttpServletResponse directly.

2. Action classes

Struts 1 requires Action classes to extend an abstract base class. Extending an abstract class instead of interface is one of design issues of struts 1.x framework that has been resolved in the struts 2 framework.
In case of Struts 2 Action class may or may not implement interfaces to enable optional and custom services. In case of Struts 2 , Actions are not container dependent because they are made simple POJOs. Struts 2 provides a base ActionSupport class to implement commonly used interfaces. Albeit, the Action interface is not required. Any POJO object with an execute signature can be used as an Struts 2 Action object. Struts 2 also provides a way to maintain action objects using spring container.

3. Validation


Struts1 and Struts 2 both supports the manual validation via a validate method.
Struts1 uses validate method on the ActionForm, or validates through an extension to the Commons Validator. However, Struts 2 supports manual validation via the validate method and the XWork Validation framework. The Xwork Validation Framework supports chaining validation into sub-properties using the validations defined for the properties class type and the validation context.

4. Threading Model

In Struts1, Action resources must be thread-safe or synchronized. So Actions are singletons and thread-safe, there should only be one instance of a class to handle all requests for that Action. The singleton strategy places restrictions on what can be done with Struts1 Actions and requires extra care to develop. However in case of Struts 2, Action objects are instantiated for each request, so there are no thread-safety issues. (In practice, servlet containers generate many throw-away objects per request, and one more object does not impose a performance penalty or impact garbage collection.)

5. Testability

Testing Struts1 applications are a bit complex. A major hurdle to test Struts1 Actions is that the execute method because it exposes the Servlet API. A third-party extension, Struts TestCase, offers a set of mock object for Struts1. But the Struts 2 Actions can be tested by instantiating the Action, setting properties and invoking methods. Dependency Injection support also makes testing simpler. Actions in struts2 are simple POJOs and are framework independent, hence testability is quite easy in struts2.

6. Harvesting Input

Struts1 uses an ActionForm object to capture input. And all ActionForms needs to extend a framework dependent base class. JavaBeans cannot be used as ActionForms, so the developers have to create redundant classes to capture input.
However Struts 2 uses Action properties (as input properties independent of underlying framework) that eliminates the need for a second input object, hence reduces redundancy. Additionally in struts2, Action properties can be accessed from the web page via the taglibs. Struts 2 also supports the ActionForm pattern, as well as POJO form objects and POJO Actions. Even rich object types, including business or domain objects, can be used as input/output objects.

7. Expression Language

Struts1 integrates with JSTL, so it uses the JSTL-EL. The struts1 EL has basic object graph traversal, but relatively weak collection and indexed property support. Struts 2 can also use JSTL, however it supports a more powerful and flexible expression language called "Object Graph Notation Language" (OGNL).

8. Binding values into views

In the view section, Struts1 uses the standard JSP mechanism to bind objects (processed from the model section) into the page context to access. However Struts 2 uses a "ValueStack" technology so that the taglibs can access values without coupling your view to the object type it is rendering. The ValueStack strategy allows the reuse of views across a range of types which may have the same property name but different property types.

9. Type Conversion

Usually, Struts1 ActionForm properties are all Strings. Struts1 uses Commons-Beanutils for type conversion. These type converters are per-class and not configurable per instance. However Struts 2 uses OGNL for type conversion. The framework includes converters for basic and common object types and primitives.

10. Control Of Action Execution

Struts1 supports separate Request Processor (lifecycles) for each module, but all the Actions in a module must share the same lifecycle. However Struts 2 supports creating different lifecycles on a per Action basis via Interceptor Stacks. Custom stacks can be created and used with different Actions as needed.


Comparison of struts 2 with struts 1, comparing struts 1 and Struts 2, struts 1 or struts 2 which one to use, struts 2 vs struts 1

Struts 2 - AJAX Drop down Example


Struts2 AJAX Drop down Example, struts2 ajax auto populate drop down, struts2 ajax auto select drop down, Struts2 AJAX Example, Struts2 AJAX Drop down sample Code, Struts 2, beginners example for struts2, struts2 simple application,struts2 with ajax

Struts 2 is a powerful web application development framework. Its built on top of WebWork framework and rebranded as Struts 2. Due to excessive popularity of Struts 1 its difficult to search for much relevant documentation on web about struts2. Slowly the search engines are improving on that.

In this example when you select from one drop down the other will populate accordingly. You can use it as is or play around with it based on your need

Index.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>



Listing.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>
   
   
   
    Listing
   
   
   
   
   
   
   
   
   
   
    onchange="javascript:show_details();return false;" >
   
    id="details" href="%{d_url}" theme="ajax"
    listenTopics="show_detail" formId="frm_demo">
   

   

   
   


Detail.jsp

<%@ taglib prefix="s" uri="/struts-tags"%>






DetailAction.java

package ajaxdemo.action;

import java.util.ArrayList;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;

public class DetailAction extends ActionSupport {
private String lst;
private List lstList = null;
private List lstList2 = null;

public String execute() throws Exception {

if (getLst() != null && !getLst().equals("")) {
populateDetail(getLst());
return SUCCESS;
} else {
return SUCCESS;
}
}

private void populateDetail(String id) {
lstList = new ArrayList();
if (id.equalsIgnoreCase("Fruits")) {
lstList.add("Apple");
lstList.add("PineApple");
lstList.add("Mango");
lstList.add("Banana");
lstList.add("Grapes");
} else if (id.equalsIgnoreCase("Places")) {
lstList.add("New York");
lstList.add("Sydney");
lstList.add("California");
lstList.add("Switzerland");
lstList.add("Paris");
} else {
lstList.add("Other 1");
lstList.add("Other 2");
lstList.add("Other 3");
lstList.add("Other 4");
lstList.add("Other 5");
}
}

public List getLstList() {
return lstList;
}

public void setLstList(List lstList) {
this.lstList = lstList;
}

public String getLst() {
return lst;
}

public void setLst(String lst) {
this.lst= lst;
}
}


DetailListing.java


package ajaxdemo.action;

import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;

public class ListingAction extends ActionSupport {
private List lstList1 = null;

public String execute() throws Exception {
populateDetail();
return SUCCESS;
}

private void populateDetail() {
lstList1 = new ArrayList();
lstList1.add("Fruits");
lstList1.add("Places");
lstList1.add("Others");

}

public List getLstList1() {
return lstList1;
}

public void setLstList1(List lstList1) {
this.lstList1 = lstList1;
}
}


Struts.xml


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">



/listing.jsp


/detail.jsp





web.xml




struts2
org.apache.struts2.dispatcher.FilterDispatcher


struts2
/*


index.jsp


Important things to know before go live

It is of the upmost importance that your website practices good web design techniques which will enable your website to get the maximum amount of traffic, therefore making the maximum amount of profit.

Standards


The most important thing to consider on the World Wide Web is that your website/blog reaches certain web standards. These are set out at www.w3.org. Your website may look good in commonly used browsers like Internet Explorer, Firfox and Safari, if layout desing breaks you WILL lose visitors. Around 45% of people worldwide use Internet Explorer, 35% Firefox and 20% other browsers so that’s 55 peoples out of every 100 that visit your site using a different browser so cross-browser support MUST be considered.

Navigation Navigation


Ensure your navigation should be easy as possible, make sure it is clear and concise and that at any point of a visitors browsing they know where they are and how to get back to where they came from. If a visitor experiences any confusion in any way they Will leave your website.

ContentContent


Text paragraphs should always be kept at reasonable lengths. If a block of text appears to be too big it can deter some a lot of visitors from reading your content. If you have got a lot of content to go on a page you should always try and split them into small text blocks, this way visitors will be able to pick out what they need to know a lot easier and they will not feel as though they are reading an essay.

IMAGES
If you are using any images, make sure they are optimized to the smallest possible size and try and reduce the number per page. Images will slow the loading of a website down and the majority of the time they aren’t really necessary.

SCRIPTS
Stay away from using any sort of scripting languages throughout your website for visual images/effects. Scripting can slow down the loading time of a page on your website and even cause the browsers, in some cases, to crash. If you really have to use them, export the code to a different page and reference it when needed.

CSS
Lastly, make your pages with CSS, this reduces the amount of code on your web pages enabling them to load quicker and it also saves you a lot of time when re-styling or adjusting the web site in the future.

Plogger: A free open source photo gallery system

Open source photo galleryPlogger is the next generation in open-source photo gallery systems. A web application not bloated with superfluous features or complicated configuration settings. Plogger is a simple yet powerful tool — everything you need to share your images with the world. Plogger is your photos integrated into your website, a fully featured photo sharing package with an attractive and easy to use administrative interface that makes managing your galleries a breeze. Integrating our gallery software into your website is as easy as inserting three lines of PHP code. Plogger requires a server setup with at least MySQL v3.23, GD1.0, and PHP4.

Click here to download | Visit website

Photo modifier software that improves your looks

E-TOUCH UPWant to optimise your looks without radically altering them? An Israeli team of computer scientists may have the answer. They have developed a computer software model based on the innate preferences that studies show we have for human faces.

"This technology could become a product where for example there's a web service where people upload their photographs and have them enhanced or beautified by our software," said Professor Dani Lischinksi of Hebrew University in Jerusalem.

Studies show that eyes a certain shape and distance apart, nose a certain length, lips a certain curve, increase the probability that we will find one face more attractive than another.

"We were able to fit a mathematical model to this set of data that we've gathered, namely the images that we showed to people and their responses in terms of the beauty scores that they chose to give to each image," said Lischinksi.

The team then applied the model to modify images so as to make them appear more attractive. They are now exploring a variety of potential commercial applications for the software, Lischinski said.

"This is something we're looking into," he said. It remains to be seen whether women would simply use the improved image as a guide to more effective makeup application or whether people take it to a plastic surgeon and say: "Make me look like that."

SUBTLE SHIFTS

The results can be striking. The photographed face of one conventionally pretty woman processed by what some Israeli media dubbed "the beauty machine" became clearly more beautiful.

Crucially, the software did not attempt to correct the very slight crookedness in her nose, so she was unmistakably the same person but subtly enhanced to great effect.

The aim is not a world "where everybody looks the same or everybody looks like a Hollywood star or a supermodel. What our programme tries to do is to improve the perceived attractiveness of the face but in a manner that tries to change as little as possible," said the professor.

The Israeli scientists say they are well aware of the adage that "beauty is in the eye of the beholder". "I think obviously the original faces have more. They represent the true character of that face and when we modify the image some of that character might go away. This is one possible criticism," Lischinksi said.

So far, the model simply presents the optimised version of a face which could be used as a photograph — if the owner was prepared to disappoint in any real-life encounter.

Some of those asked did not prefer the "improved" looks of movie stars, for example. "I think a lot of it has to do with familiarity," Lischinski said. But if the face is anonymous, the modified version is strongly preferred, the team's trials have shown.

A random trial among Jerusalem women was inconclusive. One woman said she would not use the programme "because then you see yourself in the perfect light and no one is perfect... It's impossible and it's unethical and it will just make you upset."

The software also demands high-quality photographs taken head-on. Blurred images or tilted chins defeat it.

Leonardo da Vinci's Mona Lisa loses her enigmatic smile and appears horribly distorted, her lips like those of a cartoon witch.

source:ibnlive.com

Photoshop Tutorial: How to create Shiny Starburst Effect

In this post you will learn how to create shiny starburst effect by using photoshop. Following the simple steps to create a shiny starburst effect:



Step 1

Open your canvas. Press D. (to set default foreground and background colors) Press Alt+Backspace to fill canvas with black color. Duplicate the layer ( right click on the current layer on the layer's panel and select 'duplicate layer '). Continue working on this new layer.

Step 2

Select the gradient tool from the tool bar, place the cursor at the bottom of the canvas, click and drag it to the top of the canvas. Now your canvas has a black and white gradient fill.

Step 3

photoshop tutorial: shiny starburst effect

Click on Filter>Distort>Wave the Wave window appears, give the settings as in the image on the right.

Step 4

Click on Filter>Distort>Polar Coordinates. The polar coordinates window opens up, give the settings as 100% and check the 'Rectangular to Polar' option.

Step 5

Click on Image>Adjustments>Hue/ Saturation and change the settings to : Hue - 200, Saturation - 25 and Lightness - 0. Check the Colorize option

Step 6

Next click on Filter>Render>Lighting Effects and set the Light type to Omni let the other settings be default.



Here's the shiny star!