JSP Ajax
JSP Ajax
Ang Chen
There are several levels of scope, where each one has its
parameters:
I Container: system-wide configuration
I Application: application configuration and parameters
I Servlet: servlet information and parameters
I Page: information related with a JSP
I Session: session information can cross pages and servlets,
session can be used to store objects
Each level is modeled by a Java class or interface. (Implicit objects
in JSP)
Interface javax.servlet.Servlet
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
HttpServletRequest class
Request URL: http://localhost:8080/list.jsp?category=pinfo05
cat will have value ”pinfo05”. It works for both GET and POST requests.
function getListByCategory() {
var req = false;
var self = this;
if (window.XMLHttpRequest) {
self.req = new XMLHttpRequest(); // for Firefox and other browsers
} else if (window.ActiveXObject) {
self.req = new ActiveXObject("Microsoft.XMLHTTP"); // for IE browser
}
// when the request is finished, call this function
self.req.onreadystatechange = processRequest;
self.req.open("GET", url, true); // it is a GET request
self.req.send(null); // send the request
}
<div id=result></div>
function processRequest() {
// check the request state is "complete"
if (req.readyState == 4 || req.readyState == "complete") {
if (req.status == 200) {
updatepage(self.req.responseText);
} else {
alert("Not able to retrieve member list");
}
}
}
// Just set the content of note with id "result" with the input parameter
// Other DOM and XML operations are possible, here it is simplified.
function updatepage(str) {
document.getElementById("result").innerHTML = str;
}
AJAX: Web Application Model
Specifications:
I Java Servlet Specifications
I JSP Technology
Tutorial:
I Basic Servlets:
http://www.apl.jhu.edu/ hall/java/Servlet-Tutorial/
I MoreServlets Book & Tutorials: Servlet, JSP, Taglib, Struts,
AJAX
AJAX, WEB 2.0
AJAX:
I Ajax: A New Approach to Web Applications
I AJAX: Getting Started, mozilla developer center
I Top 10 Ajax Applications
I AJAX Tutorial
I AJAX Login System Demo
I Guide to Using AJAX and XMLHttpRequest
I Ajaxian
WEB 2.0
I O’Reilly: What Is Web 2.0
I The Best Web 2.0 Software of 2005
I Writly
I Google Earth