2006年06月21日

    今天试着装了一下Globus, 在一台机器上现在算是装上了,启动的时候有些问题,应该是没装数据库的原因.但是有个问题?

    在一台机器上装上Globus后,还要在其它的机器上安装吗(几台想互连的机器)?证书是如何获得的.怎么来用呢?看来要学的东西还有很多啊.

    Globus好像有两个Core组件,一个是C的,一个是Java的.我应该会用Java那部分的.要好好看看Globus的文档了,不然过一段时间就没办法开发CSF了.

    现在的主要任务是把两台机器连进来….

2005年11月17日

#include<stdio.h>
#include<stdlib.h>

#define SIZE 21

int read();
int isPossible();

int main(){
  while(read())
    printf("%s\n",isPossible()?"Possible":"Impossible");
  return 0;
}

static int q[SIZE],p[SIZE];
static int n,cost;


int compare(void const* a,void const* b){
  return *(int*)a-*(int*)b;
}

int read(){
  if(scanf("%d %d",&n,&cost)!=2)
    return 0;
  int i;
  for(i=0;i<n;i++)
    if(scanf("%d",q+i)!=1)
      return 0;
  for(i=0;i<n;i++)
    if(scanf("%d",p+i)!=1)
      return 0;
  qsort(q,n,sizeof(int),compare);
  qsort(p,n,sizeof(int),compare);
  return 1;
}

int getRMaxCost(int i,int*v){
        /* 计算剩下的最大值 */
  int r_max_cost=0,j,k;
  for(j=i,k=1;j<n;j++){
    while(k<=n && v[k])
      k++;
    if(k<=n)
      r_max_cost+=q[k-1]*p[j];
    k++;
  }
  return r_max_cost;
}

int getRMinCost(int i,int*v){
        /* 计算剩下的最小值 */
  int r_min_cost=0,j,k;
  for(j=i,k=n;j<n;j++){
    while(k>0 && v[k])
      k–;
    if(k>0)
      r_min_cost+=q[k-1]*p[j];
    k–;
  }
  return r_min_cost;
}

int isPossible(){
  int v[SIZE]={0};
  int log[SIZE]={0};
  int i=0,sum=0,add;
  int r_max_cost,r_min_cost;
  int j,k;
  while(i>=0){

    v[log[i]]=0;
    log[i]++;

    while( v[log[i]] && log[i]<=n )
      log[i]++;

    if(log[i]<=n){

      if(i==n-1 && sum+q[log[i]-1]*p[i]==cost)
        return 1;

      else{

        r_max_cost=getRMaxCost(i,v);
        r_min_cost=getRMinCost(i,v);

        if(sum+r_max_cost<cost ||
           sum+r_min_cost>cost){
          i–;
          if(i>=0)
            sum-=q[log[i]-1]*p[i];
          continue;
        }
        /* 是否是一可行解 */
        if(sum+r_min_cost==cost ||
           sum+r_max_cost==cost)
          return 1;
        /* 记录当前状态 */
        sum+=q[log[i]-1]*p[i];
        v[log[i]]=1;
        i++;
        log[i]=0;
      }
    }else{
      /* 回溯 */
      i–;
      if(i>=0)
        sum-=q[log[i]-1]*p[i];
    }
  }
  return 0;
}

2005年11月07日

#include<cstdio>
using namespace std;

class Booklet{
private:
 int pages;
public:
 bool read();
 void print();
};

bool Booklet::read(){
 if(scanf("%d",&pages)!=1)
  return false;
 return pages!=0;
}

void Booklet::print(){
 printf("Printing order for %d pages:\n",pages);
 int sheets=(pages%4==0)?(pages/4):(pages/4+1);
 int* book=new int[sheets*4];
 int i,j;
 for(i=1;i<=pages;i++)
  book[i-1]=i;
 for(;i<=sheets*4;i++)
  book[i-1]=0;
 int len=sheets*2;
 int page=1;
 for(i=0,j=sheets*4-1;i<len;i+=2,j-=2,page++){
  if(book[j]!=0 || book[i]!=0)
   if(book[j]==0)
    printf("Sheet %d, front: Blank, %d\n",page,book[i]);
   else if(book[i]==0)
    printf("Sheet %d, front: %d, Blank\n",page,book[j]);
   else
    printf("Sheet %d, front: %d, %d\n",page,book[j],book[i]);
  if(book[j-1]!=0 || book[i+1]!=0)
   if(book[j-1]==0)
    printf("Sheet %d, back : %d, Blank\n",page,book[i+1]);
   else if(book[i+1]==0)
    printf("Sheet %d, back : Blank, %d\n",page,book[j-1]);
   else
    printf("Sheet %d, back : %d, %d\n",page,book[i+1],book[j-1]);
 }
 delete[] book;
 return;
}

int main(){
 Booklet booklet;
 while(booklet.read())
  booklet.print();
 return 0;
}

#include<iostream>
#include<map>
#include<string>
using namespace std;

#define SIZE 20
class Deg{
private:
 map<string,int> list;
 int size;
 int graph[SIZE][SIZE];
 void initGraph();
 void createGraph();
public:
 bool read();
 void print();
};

void Deg::initGraph(){
 int i,j;
 for(i=0;i<SIZE;i++)
  for(j=0;j<SIZE;j++)
   i==j?graph[i][j]=0:graph[i][j]=-1;
}

bool Deg::read(){

 initGraph();

 string name,fri;
 int id=1,degs;
 cin>>size;
 for(int i=0;i<size;i++){
  cin>>name;
  if(list[name]==0)
   list[name]=id++;
  cin>>degs;
  for(int j=0;j<degs;j++){
   cin>>fri;
   if(list[fri]==0)
    list[fri]=id++;
   graph[list[name]-1][list[fri]-1]=1;
  }
 }
 return true;
}

void Deg::print(){

 createGraph();

 int times,i,dis;
 string start,goal;
 cin>>times;
 for(i=0;i<times;i++){
  cin>>start>>goal;
  dis=graph[list[start]-1][list[goal]-1];
  if(dis>0)
   cout<<start<<" is separated from "<<goal<<" by "<<dis-1<<" degrees.";
  else
   cout<<start<<" has no connection to "<<goal<<".";
  cout<<endl;
 }
}

void Deg::createGraph(){
 int i,j,k,dest;
 for(k=0;k<size;k++)
  for(i=0;i<size;i++)
   for(j=0;j<size;j++)
    if(graph[i][k]!=-1 && graph[k][j]!=-1){
     dest=graph[i][k]+graph[k][j];
     if(graph[i][j]==-1)
      graph[i][j]=dest;
     else if(graph[i][j]>dest)
      graph[i][j]=dest;
    }
}

int main(){
 Deg deg;
 deg.read();
 deg.print();
 return 0;
}

2005年09月28日

Build dynamic Java applications

Level: Intermediate

Philip McCarthy (philmccarthy@gmail.com), Software Development Consultant, Independent Consultant

20 Sep 2005

The page-reload cycle presents one of the biggest usability obstacles in Web application development and is a serious challenge for Java™ developers. In this series, author Philip McCarthy introduces a groundbreaking approach to creating dynamic Web application experiences. Ajax (Asynchronous JavaScript and XML) is a programming technique that lets you combine Java technologies, XML, and JavaScript for Java-based Web applications that break the page-reload paradigm.

Ajax, or Asynchronous JavaScript and XML, is an approach to Web application development that uses client-side scripting to exchange data with the Web server. As a result, Web pages are dynamically updated without a full page refresh interrupting the interaction flow. With Ajax, you can create richer, more dynamic Web application user interfaces that approach the immediacy and usability of native desktop applications.

Ajax isn’t a technology, it’s more of a pattern — a way to identify and describe a useful design technique. Ajax is new in the sense that many developers are just beginning to be aware of it, but all of the components that implement an Ajax application have existed for several years. The current buzz is because of the emergence in 2004 and 2005 of some great dynamic Web UIs based on Ajax technology, most notably Google’s GMail and Maps applications and the photo-sharing site Flickr. These UIs were sufficiently groundbreaking to be dubbed "Web 2.0" by some developers, with the resulting interest in Ajax applications skyrocketing.

In this series, I’ll give you all the tools you need to begin developing your own applications using Ajax. In this first article, I’ll explain the concepts behind Ajax and demonstrate the fundamental steps to creating an Ajax interface for a Java-based Web application. I’ll use code examples to demonstrate both the server-side Java code and the client-side JavaScript that make Ajax applications so dynamic. Finally, I’ll point out some of the pitfalls of the Ajax approach, as well as the broader usability and accessibility issues you should consider when creating Ajax applications.

A better shopping cart

You can use Ajax to enhance traditional Web applications, streamlining interaction by eliminating page loads. To demonstrate this, I’ll use the simple example of a shopping cart that is dynamically updated as items are added to it. Incorporated into an online store, this approach would let users continue browsing and adding items to their carts without having to wait after each click for a full-page update. While some of the code in this article is specific to the shopping cart example, the techniques illustrated can be applied to any Ajax application. Listing 1 shows the relevant HTML code the shopping-cart example uses. I’ll refer back to this HTML throughout the article.


Listing 1. Relevant fragments of the shopping cart example



<!-- Table of products from store's catalog, one row per item -->
<th>Name</th> <th>Description</th> <th>Price</th> <th></th>
...
<tr>
  <!-- Item details -->
  <td>Hat</td> <td>Stylish bowler hat</td> <td>$19.99</td>
  <td>
    <!-- Click button to add item to cart via Ajax request -->
    <button onclick="addToCart('hat001')">Add to Cart</button>
  </td>
</tr>
...

<!-- Representation of shopping cart, updated asynchronously -->
<ul id="cart-contents">

  <!-- List-items will be added here for each item in the cart -->

</ul>

<!-- Total cost of items in cart displayed inside span element -->
Total cost: <span id="total">$0.00</span>







The Ajax roundtrip

An Ajax interaction begins with a JavaScript object called XMLHttpRequest. As the name suggests, it allows a client-side script to perform HTTP requests, and it will parse an XML server response. The first step in this Ajax roundtrip is to create an XMLHttpRequest instance. The HTTP method to use for the request (GET or POST) and the destination URL are then set on the XMLHttpRequest object.

Now, remember how that first a in Ajax stands for asynchronous? When you send that HTTP request, you don’t want the browser to hang around waiting for the server to respond. Instead, you want it to continue reacting to the user’s interaction with the page and deal with the server’s response when it eventually arrives. To accomplish this, you can register a callback function with the XMLHttpRequest and then dispatch the XMLHttpRequest asynchronously. Control then returns to the browser, but the callback function will be called when the server’s response arrives.

On the Java Web server, the request arrives just like any other HttpServletRequest. After parsing the request parameters, the servlet invokes the necessary application logic, serializes its response into XML, and writes it to the HttpServletResponse.

Back on the client side, the callback function registered on the XMLHttpRequest is now invoked to process the XML document returned by the server. Finally, the user interface is updated in response to the data from the server, using JavaScript to manipulate the page’s HTML DOM. Figure 1 is a sequence diagram of the Ajax roundtrip.


Figure 1. The Ajax roundtrip
Sequence diagram of the Ajax roundtrip

Now that you have a high-level view of the Ajax roundtrip, I’ll zoom in for a more detailed look at each step along the way. Refer back to Figure 1 if you lose your place — the sequence isn’t entirely straightforward because of the asynchronous nature of the Ajax approach.





Dispatching an XMLHttpRequest

I’ll start at the beginning of the Ajax sequence: creating and dispatching an XMLHttpRequest from the browser. Unfortunately, the method to create an XMLHttpRequest differs from browser to browser. The JavaScript function in Listing 2 smoothes out these browser-dependent wrinkles, detecting the correct approach for the current browser and returning an XMLHttpRequest ready to use. It’s best to think of this as boilerplate code: simply copy it into your JavaScript library and use it when you need an XMLHttpRequest.


Listing 2. Creating a cross-browser XMLHttpRequest


/*
 * Returns a new XMLHttpRequest object, or false if this browser
 * doesn't support it
 */
function newXMLHttpRequest() {

  var xmlreq = false;

  if (window.XMLHttpRequest) {

    // Create XMLHttpRequest object in non-Microsoft browsers
    xmlreq = new XMLHttpRequest();

  } else if (window.ActiveXObject) {

    // Create XMLHttpRequest via MS ActiveX
    try {
      // Try to create XMLHttpRequest in later versions
      // of Internet Explorer

      xmlreq = new ActiveXObject("Msxml2.XMLHTTP");

    } catch (e1) {

      // Failed to create required ActiveXObject

      try {
        // Try version supported by older versions
        // of Internet Explorer

        xmlreq = new ActiveXObject("Microsoft.XMLHTTP");

      } catch (e2) {

        // Unable to create an XMLHttpRequest with ActiveX
      }
    }
  }

  return xmlreq;
}


Later, I’ll discuss techniques to handle browsers that don’t support XMLHttpRequest. For now, the examples assume that the newXMLHttpRequest function from Listing 2 will always return an XMLHttpRequest instance.

Getting back to the example shopping-cart scenario, I want to invoke an Ajax interaction whenever the user hits the Add to Cart button for a catalog item. The onclick handler function named addToCart() is responsible for updating the state of the cart through an Ajax call (see Listing 1). As shown in Listing 3, the first thing that addToCart() needs to do is obtain an instance of XMLHttpRequest by calling the newXMLHttpRequest() function from Listing 2. Next, it registers a callback function to receive the server’s response (I’ll explain this in detail later; see Listing 6).

Because the request will modify state on the server, I’ll use an HTTP POST to do the deed. Sending data through POST requires three steps. First, I need to open a POST connection to the server resource I’m communicating with — in this case a servlet mapped to the URL cart.do. Next, I set a header on the XMLHttpRequest stating that the content of the request is form-encoded data. Finally, I send the request with form-encoded data as the body.

Listing 3 puts these steps together.


Listing 3. Dispatching an Add to Cart XMLHttpRequest


/*
 * Adds an item, identified by its product code, to the shopping cart
 * itemCode - product code of the item to add.
 */
function addToCart(itemCode) {

  // Obtain an XMLHttpRequest instance
  var req = newXMLHttpRequest();

  // Set the handler function to receive callback notifications
  // from the request object
  var handlerFunction = getReadyStateHandler(req, updateCart);
  req.onreadystatechange = handlerFunction;

  // Open an HTTP POST connection to the shopping cart servlet.
  // Third parameter specifies request is asynchronous.
  req.open("POST", "cart.do", true);

  // Specify that the body of the request contains form data
  req.setRequestHeader("Content-Type",
                       "application/x-www-form-urlencoded");

  // Send form encoded data stating that I want to add the
  // specified item to the cart.
  req.send("action=add&item="+itemCode);
}


And with that, you’ve seen the first part of setting up the Ajax roundtrip — namely creating and dispatching the HTTP request from the client. Next up is the Java servlet code used to handle the request.






Servlet request handling

Handling an XMLHttpRequest with a servlet is largely the same as handling a regular HTTP request from a browser. The form-encoded data sent in the POST request’s body can be obtained with HttpServletRequest.getParameter() calls. Ajax requests take part in the same HttpSession as regular Web requests from the application. This is useful for the example shopping-cart scenario because it lets me encapsulate the user’s shopping-cart state in a JavaBean and persist that state to the session between requests.

Listing 4 is part of a simple servlet that handles Ajax requests to update the shopping cart. A Cart bean is retrieved from the user’s session and its state is updated according to the request parameters. The Cart is then serialized to XML, and that XML is written to the ServletResponse. It’s important to set the response’s content type to application/xml, otherwise the XMLHttpRequest will not parse the response content into an XML DOM.


Listing 4. Servlet code to handle Ajax requests


public void doPost(HttpServletRequest req, HttpServletResponse res)
                        throws java.io.IOException {

  Cart cart = getCartFromSession(req);

  String action = req.getParameter("action");
  String item = req.getParameter("item");

  if ((action != null)&&(item != null)) {

    // Add or remove items from the Cart
    if ("add".equals(action)) {
      cart.addItem(item);

    } else if ("remove".equals(action)) {
      cart.removeItems(item);

    }
  }

  // Serialize the Cart's state to XML
  String cartXml = cart.toXml();

  // Write XML to response.
  res.setContentType("application/xml");
  res.getWriter().write(cartXml);
}


Listing 5 shows an example of the XML produced by the Cart.toXml() method. It’s pretty straightforward. Note the generated attribute on the cart element, which is a timestamp produced by System.currentTimeMillis().


Listing 5. Example XML serialization of the Cart object


<?xml version="1.0"?>
<cart generated="1123969988414" total="$171.95">
  <item code="hat001">
    <name>Hat</name>
    <quantity>2</quantity>
  </item>
  <item code="cha001">
    <name>Chair</name>
    <quantity>1</quantity>
  </item>
  <item code="dog001">
    <name>Dog</name>
    <quantity>1</quantity>
  </item>
</cart>


If you take a look at Cart.java in the application source code available from the Download section, you’ll see that the XML is produced simply by appending strings together. While sufficient for this example, this is pretty much the worst way to produce XML from Java code. I’ll suggest some better approaches in the next installment of this series.

So now you know how the CartServlet responds to an XMLHttpRequest. The next thing is to return to the client side, where you can see how the XML response is used to update page state.






Response handling with JavaScript

The readyState property of XMLHttpRequest is a numeric value that gives the status of the request’s lifecycle. It changes from 0 for "uninitialized" through to 4 for "complete." Each time the readyState changes, the readystatechange event fires and the handler function attached via the onreadystatechange property is called.

In Listing 3, you saw how the function getReadyStateHandler() was called to create a handler function. This handler function was then assigned to the onreadystatechange property. getReadyStateHandler() exploits the fact that functions are first-class objects in JavaScript. This means that functions can be parameters to other functions and can also create and return other functions. It is the job of getReadyStateHandler() to return a function that checks whether the XMLHttpRequest has completed and passes the XML response onto the handler function specified by the caller. Listing 6 is the code for getReadyStateHandler().


Listing 6. The getReadyStateHandler() function


/*
 * Returns a function that waits for the specified XMLHttpRequest
 * to complete, then passes its XML response to the given handler function.
 * req - The XMLHttpRequest whose state is changing
 * responseXmlHandler - Function to pass the XML response to
 */
function getReadyStateHandler(req, responseXmlHandler) {

  // Return an anonymous function that listens to the
  // XMLHttpRequest instance
  return function () {

    // If the request's status is "complete"
    if (req.readyState == 4) {

      // Check that a successful server response was received
      if (req.status == 200) {

        // Pass the XML payload of the response to the
        // handler function
        responseXmlHandler(req.responseXML);

      } else {

        // An HTTP problem has occurred
        alert("HTTP error: "+req.status);
      }
    }
  }
}



HTTP status codes

In Listing 6, the status property of XMLHttpRequest is tested to see if the request completed successfully. status contains the HTTP status code of the server’s response. When performing simple GET and POST requests, you can assume that any code other than 200 (OK) is an error. If the server sends a redirect response (for example, 301 or 302), the browser transparently follows the redirect and fetches the resource from the new location; the XMLHttpRequest doesn’t see the redirect status code. Also, browsers automatically add a Cache-Control: no-cache header to all XMLHttpRequests, so client code will never have to deal with a 304 (not-modified) server response either.

About getReadyStateHandler()

getReadyStateHandler() is a relatively complex piece of code, especially if you’re not used to reading JavaScript. The trade-off is that by including this function in your JavaScript library, you can simply handle Ajax server responses without having to deal with the internals of XMLHttpRequest. The important thing is that you understand how to use getReadyStateHandler() in your own code.

In Listing 3, you saw getReadyStateHandler() called as follows: handlerFunction = getReadyStateHandler(req, updateCart). The function returned by getReadyStateHandler() in this case will check if the XMLHttpRequest in the variable req has completed and then call a function named updateCart with the response XML.

Extracting the cart data

Listing 7 is the code of updateCart() itself. The function interrogates the shopping cart XML document using DOM calls and updates the Web page (see Listing 1) to reflect the new cart contents. Focus here on the calls used to extract data from the XML DOM. The generated attribute on the cart element, a timestamp created when the Cart was serialized to XML, is checked to ensure that newer cart data is not overwritten by older cart data. Ajax requests are inherently asynchronous, so this check safeguards against server responses that arrive out of sequence.


Listing 7. Updating the page to reflect the cart XML document


function updateCart(cartXML) {

 // Get the root "cart" element from the document
 var cart = cartXML.getElementsByTagName("cart")[0];

 // Check that a more recent cart document hasn't been processed
 // already
 var generated = cart.getAttribute("generated");
 if (generated > lastCartUpdate) {
   lastCartUpdate = generated;

   // Clear the HTML list used to display the cart contents
   var contents = document.getElementById("cart-contents");
   contents.innerHTML = "";

   // Loop over the items in the cart
   var items = cart.getElementsByTagName("item");
   for (var I = 0 ; I < items.length ; I++) {

     var item = items[I];

     // Extract the text nodes from the name and quantity elements
     var name = item.getElementsByTagName("name")[0]
                                               .firstChild.nodeValue;

     var quantity = item.getElementsByTagName("quantity")[0]
                                               .firstChild.nodeValue;

     // Create and add a list item HTML element for this cart item
     var li = document.createElement("li");
     li.appendChild(document.createTextNode(name+" x "+quantity));
     contents.appendChild(li);
   }
 }

 // Update the cart's total using the value from the cart document
 document.getElementById("total").innerHTML =
                                          cart.getAttribute("total");
}


And with that, the whistle-stop tour of the Ajax roundtrip is complete, although you may want to get the Web app running and see it in action (see the Download section). The example is very simple, with plenty of scope for improvement. For instance, I’ve included server-side code to remove items from the cart, but no way to access it from the UI. For a good exercise, try building on the application’s existing JavaScript code to implement this functionality.





Challenges of using Ajax

As with any technology, there are plenty of ways to make mistakes with Ajax. Some of the problems I discuss here currently lack easy solutions but will improve as Ajax matures. As the developer community gains experience developing Ajax applications, best practices and guidelines will be documented.

Availability of XMLHttpRequest

One of the biggest issues facing Ajax developers is how to respond when XMLHttpRequest isn’t available. While the majority of modern browsers support XMLHttpRequest, there will always be a minority of users whose browsers do not, or whose browser security settings prevent XMLHttpRequest from being used. If you’re developing a Web app to be deployed on a corporate intranet, you probably have the luxury of specifying which browsers are supported and assuming XMLHttpRequest is always available. If you’re deploying on the public Web, however, you must be aware that by presuming XMLHttpRequest is available, you are potentially preventing users of older browsers, browsers for people with disabilities, or lightweight browsers on handheld devices from using your application.

Therefore, you should endeavor to make your application "degrade gracefully" and remain functional in browsers without XMLHttpRequest support. In the shopping-cart example, the best way to degrade the application would be to have the Add to Cart buttons perform a regular form submission, refreshing the page to reflect the cart’s updated status. The Ajax behavior could be added to the page through JavaScript once the page was loaded, attaching a JavaScript handler function to each Add to Cart button only if XMLHttpRequest was available. Another approach would be to detect XMLHttpRequest when a user logged in, and then serve up either an Ajax version of the application or a regular forms-based version as appropriate.

Usability concerns

Some of the usability issues surrounding Ajax applications are more general. For instance, it can be important to let users know that their input has been registered, because the usual feedback mechanisms of the hourglass cursor and spinning browser "throbber" do not apply to XMLHttpRequests. One technique is to replace Submit buttons with a "Now updating…" type message so that users do not repeatedly click on buttons while waiting for a response.

Another issue is that users may fail to notice that parts of the page they’re viewing have been updated. You can alleviate this problem by using a variety of visual techniques to subtly draw the user’s eye to updated areas of the page. Other issues caused by updating the page with Ajax include "breaking" the browser’s back button, and the URL in the address bar not reflecting the entire state of the page, preventing bookmarking. See the Resources section for articles that specifically address the usability issues of Ajax applications.

Server load

Implementing an Ajax UI in place of a regular forms-based one may dramatically increase the number of requests made to the server. For instance, a regular Google Web search causes one hit on the server, occurring when the user submits the search form. However, Google Suggest, which attempts to autocomplete your search terms, sends several requests to the server as the user types. When developing an Ajax application, be aware of how many requests you’ll be sending to the server and the resulting server load this will cause. You can mitigate server load by buffering requests on the client and caching server responses in the client, where applicable. You should also attempt to design your Ajax Web applications so that as much logic as possible can be performed on the client, without needing to contact the server.

Dealing with asynchrony

It’s very important to understand that there is no guarantee that XMLHttpRequests will complete in the order they were dispatched. Indeed, you should assume that they will not and design your application with this in mind. In the shopping-cart example, a last-updated timestamp was used to make sure that newer cart data would not be overwritten by older data (see Listing 7). This very rudimentary approach works for the shopping-cart scenario, but may not for others. Consider at design time how you will deal with asynchronous server responses.






In conclusion

You should now have a good understanding of the fundamental principles of Ajax and a nuts-and-bolts knowledge of the client- and server-side components that participate in an Ajax interaction. These are the building blocks of a Java-based Ajax Web application. In addition, you should understand some of the high-level design issues that come with the Ajax approach. Creating a successful Ajax application requires a holistic approach — from UI design through JavaScript design to server-side architecture — but you should now be armed with the core Ajax knowledge needed to consider these other aspects.

There’s good news if you’re feeling daunted by the complexity of writing a large Ajax application using the techniques demonstrated here. Just as frameworks like Struts, Spring, and Hibernate have evolved to abstract Web application development away from the low-level details of the Servlet API and JDBC, so toolkits are appearing to ease Ajax development. Some of these focus solely on the client side, providing easy ways to add visual effects to your pages or streamlining the use of XMLHttpRequest. Others go further, providing means to automatically generate Ajax interfaces from server-side code. These frameworks do the heavy lifting for you, so that you can take a more high-level approach to Ajax development. I’ll be looking at some of them in this series.

The Ajax community is fast moving, and there’s a great deal of valuable information out there. Before reading the next installment in this series, I recommend that you consult the articles listed in the Resources section, especially if you’re new to Ajax or client-side development. You should also take some time to study the example source code and think about ways to improve it.

In the next article in this series, I’ll discuss the XMLHttpRequest API in more detail and suggest ways to create XML easily from your JavaBeans. I’ll also show you alternatives to XML for Ajax data transfer, such as the JSON (JavaScript Object Notation) lightweight data-interchange format.







Resources

Learn


Get products and technologies

  • Mozilla Firefox: The DOM Inspector and JavaScript Debugger extension take a lot of the pain out of Ajax development.


Discuss






About the author

Philip McCarthy is software development consultant specializing in Java and Web technologies. He is currently working on Hewlett Packard’s Digital Media Platform project at HP Labs, Bristol. In recent years Phil has developed several rich Web clients employing asynchronous server communication and DOM scripting. He is glad we now have a name for them. You can get in touch with Phil at philmccarthy@gmail.com.

2005年09月23日

现在开始看H.264了,有好多东东要学了,得先补补离散数学和C++了,希望在今年能做出点东西来.

2005年09月13日

1.如果镜像是VCD之类的影碟,可以直接用mplayer播放:



mplayer cue://file[:track] [options]



2.用bchunk( http://he.fi/bchunk/ )转为ISO,这需要占用文件写入的时间:



bchunk file.bin file.cue outputfile



mount -t iso9660 outputfile /mnt/cdrom -o loop



3.使用cdemu( http://cdemu.sourceforge.net ),这是一个kernel module,比较高效:



cdemu 0 file.cue



mount -t iso9660 /dev/cdemu/0 /mnt/cdrom

2005年09月11日
2005年08月31日

  经过两天的努力,网站的框架已经建立起来了.剩下的工作就是代码的实现了.

  以下是网站中用到的类:

  Actin类:

  Action类都位于包com.osc.actions中.

  MDocument:网站文档的显示.

  MDownload:网站软件的显示.

  MIssue:新闻提交

  MLogOn:用户

  MLogOut:用户注消

  MNews:新闻列表

  MNewsDetail:新闻显示

  MProject:工程显示

  MRegist:用户注册

  MUpload:软件上传

  Bean类:

  MRole:用户简单信息

  MRoleDetail:用户详细信息

  MResource:总资源类的父类

  MText:文章类

  Monitor类:

  BeanMonitor:对Bean类进行监督

  这几天也把网站的美工做完了,虽然不怎么好看,不过总算说的过去,要是有谁愿意帮我再美化一下那就更好了.我的美工真是谁看谁想哭啊.唉....

  继续努力...把其它的部分都做完.

2005年08月30日

Full Gentoo Linux Download Mirrors

The following organizations provide a full source mirror of all files related to Gentoo Linux, including installation CDs, LiveCDs and GRP package sets.

Note: These mirrors are download mirrors. The rsync-mirrors listed here are not for individual use (i.e. emerge –sync) as that would download the full mirror instead of just the Portage tree.

North America:
OSU Open Source Lab (USA/http)
Adelie Linux (Canada)
Bishops University Computer Science Department (Canada/ftp)
Quebec Scientific Information Network (Canada/ftp)
ibiblio.org (USA/ftp)
ibiblio.org (USA/http)
rsync (USA/rsync)
gatech.edu (USA/ftp)
purdue.edu (USA/rsync)
Sandia National Labs (USA/ftp)
Indiana University (USA/ftp)
Seren Innovations (USA/http)
Seren Innovations (USA/rsync)
University of Wisconsin at Madison Chemistry Department (USA/http)
University of Wisconsin at Madison Chemistry Department (USA/ftp)
University of Colorado at Denver Linux Users Group (USA)
University of Colorado at Denver Linux Users Group (USA/ftp)
University of Colorado at Denver Linux Users Group (USA/rsync)
CCC Communications (USA)
CCC Communications (USA/ftp)
TDS Internet Services (USA)
TDS Internet Services (USA/ftp)
TDS Internet Services (USA/rsync)
NetNITCO Internet Services (USA)
NetNITCO Internet Services (USA/ftp)
Earth Surface Process Research Insti, Univ of Airzona (USA/http)
Rensselaer Polytechnic Institute (USA/http)
University of Notre Dame LUG (USA/ftp)
Arctic Network Mirrors (Canada/ftp)
Arctic Network Mirrors (Canada/http)
Open Systems at University of Florida (USA/ftp)
Llarian Networks (USA/http)
Llarian Networks (USA/ftp)
Binarycompass.org (USA/http)
Datapipe Managed Hosting (USA/http)
Datapipe Managed Hosting (USA/ftp)
CS Department at Lewis University (USA/http)
CS Department at Lewis University (USA/ftp)
CS Department at Lewis University (USA/rsync)
CS Department at Western Michigan University (USA/http)
Geographical Information Network of Alaska (USA/http)
Geographical Information Network of Alaska (USA/rsync)
Utah State University (USA/http)
Utah State University (USA/ftp)
Utah State University (USA/rsync)
LUG at Michigan Tech University (USA/ftp)
University of Mississippi (USA/http)
Argonne National Laboratory (USA/http)
Argonne National Laboratory (USA/ftp)
Argonne National Laboratory (USA/rsync)
Easynews NNTP Hosting (USA/http)
Easynews NNTP Hosting (USA/rsync)
University of Illinois-Urbana Champaign (USA/http)
University of Illinois-Urbana Champaign (USA/ftp)

South America:
Labroatory of System Administration (Brazil/http)
Labroatory of System Administration (Brazil/ftp)

Europe:
Inode (Austria)
Inode (Austria/ftp)
Vienna Univ. of Technology (Austria/http)
Vienna Univ. of Technology (Austria/ftp)
Vienna Univ. of Technology (Austria/rsync)
BELNET (Belgium)
BELNET (Belgium/ftp)
BELNET (Belgium/rsync)
ITD Network ISP (Bulgaria/ftp)
ITD Network ISP (Bulgaria/http)
Silicon Hill Mirror Site (Czech Republic/ftp)
Masaryk University Brno (Czech Republic/rsync)
Masaryk University Brno (Czech Republic/rsync)*
ftp.linux.ee (Estonia)
ftp.linux.ee (Estonia/ftp)
tut.fi (Finland)*
tut.fi (Finland/ftp)*
tut.fi (Finland/rsync)*
mir.zyrianes.net (France/http)
tu-clausthal.de (Germany/ftp)
rwth-aachen.de (Germany/ftp)
Ruhr-Universität Bochum (Germany)
Ruhr-Universität Bochum (Germany/ftp)
Ruhr-Universität Bochum (Germany/rsync)
Uni Erlangen-Nürnberg (Germany)
Uni Erlangen-Nürnberg (Germany/ftp)
Uni Erlangen-Nürnberg (Germany/ipv6 only)
Uni Erlangen-Nürnberg (Germany/ftp/ipv6 only)
Uni Muenster/JOIN (Germany/ftp)
Uni Muenster/JOIN (Germany/rsync)
Dresden University of Technology/AG DSN (Germany/ftp)
Westfaelische Wilhelms-Universitaet (Germany/ftp IPV4 & IPV6)*
Westfaelische Wilhelms-Universitaet (Germany/ftp IPV4)
Westfaelische Wilhelms-Universitaet (Germany/ftp IPV6)*
Technical University of Darmstadt (Germany/http)
Technical University of Darmstadt (Germany/rsync)
University of Applied Sciences, Esslingen (Germany/http)
University of Applied Sciences, Esslingen (Germany/ftp)
University of Applied Sciences, Esslingen (Germany/rsync)
Mesh Solutions Internet Service Provider (Germany/ftp)
Tiscali Internet Service Provider (Germany/http)
Tiscali Internet Service Provider (Germany/ftp)
Technical University Carolo-Wilhelmina (Germany/ftp)
files.gentoo.gr (Greece/ftp)
National Technical University of Athens (Greece/ftp)
National Technical University of Athens (Greece/http)
University of Ioannina (Greece/ftp)
Budapest University of Technology (Hungary/http)
ICD 2000 Ltd (Hungary/http)
Eotvos Lorand University (Hungary/http)
Eotvos Lorand University (Hungary/ftp)
RHnet (Iceland)
RHnet (Iceland/ftp)
RHnet (Iceland/rsync)
Ireland National Education and Research Network (Ireland/http)*
Ireland National Education and Research Network (Ireland/ftp)*
Hamakor FOSS Society (Israel/http)
Hamakor FOSS Society (Israel/rsync)
University of Padova (Italy)
University of Padova (Italy/rsync)
University Federico II of Naples (Italy)
Duomenu tiltas (Lithuania/ftp)
Universiteit Twente (Netherlands)
Universiteit Twente (Netherlands/ftp)
Universiteit Twente (Netherlands/rsync)
Universiteit Twente (Netherlands)*
Universiteit Twente (Netherlands/ftp)*
Universiteit Twente (Netherlands/rsync)*
Scarlet Internet (Netherlands/ftp)
Nutsbedrijven Maastricht n.v (Netherlands/ftp)
Gentoo.no / Gentoo.se (Norway/http)
Instituto Superior Técnico (Portugal)
Instituto Superior Técnico (Portugal/ftp)
Instituto Superior Técnico (Portugal/ftp)
Polish Gentoo (Poland/http)
Rzeszow University of Technology (Poland/rsync)
Rzeszow University of Technology (Poland/http)
Gdansk University of Technology (Poland/http)
Romanian Linux Users Group (Romania/ftp)
Romanian Linux Users Group (Romania/http)
Romanian Linux Users Group (Romania/rsync)
Romanian Education Network (Romania/http)
Romanian Education Network (Romania/ftp)
Gentoo.sk (Slovakia/http)
Aiya Mirror (Russia/http)
Aiya Mirror (Russia/ftp)
Aiya Mirror (Russia/rsync)
Citkit.ru (Russia/http)
Citkit.ru (Russia/ftp)
Catalan GNU/Linux User Group (Spain/http)
Catalan GNU/Linux User Group (Spain/ftp)
LinUV at Valencia University (Spain/http)
Hogskolan Dalarna, Dalarna (Sweden/ftp)
Hogskolan Dalarna, Dalarna (Sweden/http)
högskolan Trollhättan (Sweden/http)
Pudas mirror project (Sweden/http)
Pudas mirror project (Sweden/ftp)
SWITCHmirror (Switzerland/http)*
SWITCHmirror (Switzerland/ftp)*
SolNet (Switzerland/ftp)
SolNet (Switzerland/http)
Ankara University (Turkey/http)
Ankara University (Turkey/ftp)
Ankara University (Turkey/rsync)
Blueyonder ISP (UK/http)
Blueyonder ISP (UK/ftp)
The UK Mirror Service (UK/http)
The UK Mirror Service (UK/ftp)
The UK Mirror Service (UK/rsync)
University of Belgrade (Yugoslavia/http)
University of Belgrade (Yugoslavia/ftp)
University of Belgrade (Yugoslavia/rsync)

Australia:
PlanetMirror
PlanetMirror (ftp)
Pacific Internet
Pacific Internet (ftp)
Independent Services Providers (http)
Independent Services Providers (ftp)
Independent Services Providers (rsync)

Asia:
mirror.gentoo.gr.jp (Japan)
gg3.net (Japan)
gg3.net (Japan/ftp)
University of Tokyo (Japan/ftp)
ChannelX.biz (Japan/http)
gentoo.or.kr (South Korea)
KEMS-Zajil (Kuwait)
KEMS-Zajil (Kuwait/ftp)
linux.ntcu.net (Taiwan/rsync)
Tainan Educational Network Center (Taiwan/http)
SiamCellPhone Mirror (Thailand/http)
SiamCellPhone Mirror (Thailand/ftp)
I-Shou University (Taiwan/http)
I-Shou University (Taiwan/ftp)
Asian Open Source Centre (Malaysia/http)

Other Mirrors:
(worldwide ibiblio mirrors)

Mirroring Resources:
How to set up a Gentoo Linux rsync mirror
How to set up a Gentoo Linux source mirror

Note: * Supports IPv6

Partial Gentoo Linux Mirrors

The following organizations provide partial mirrors of Gentoo Linux, including source tarballs and snapshots of the Portage tree. These mirrors do not have copies of our installation CDs, LiveCDs or GRP package sets. Please see the above mirrors if you are looking for one of those items. Linux Kullanicilari Dernegi (Turkey/ftp)
Averse Mirror Service (Singapore/ftp)
Averse Mirror Service (Singapore/http)