buffalo之hello world,buffalohelloworld

來源:互聯網
上載者:User

buffalo之hello world,buffalohelloworld

一個國產的ajax架構,定義了Web遠程調用的傳輸基礎,

並且將遠程調用對象完整的序列化到了本地,成為可以被JavaScript編程觸及的對象。


配置依賴包:

<dependency><groupId>net.buffalo</groupId><artifactId>buffalo</artifactId><version>2.0</version></dependency>

註:由於我是手動安裝到maven本地倉庫,自訂一個座標,你也可以直接放到WEB-INF/lib下


配置web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"id="WebApp_ID" version="2.5"><servlet><servlet-name>bfapp</servlet-name><servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class></servlet><servlet-mapping><servlet-name>bfapp</servlet-name><url-pattern>/bfapp/*</url-pattern></servlet-mapping></web-app>



HelloService:

package com.demo;public class HelloService {public String sayHi(String name){System.out.println("hello "+name);return "hello world";}}


設定檔;

buffalo-service.properties:

## Buffalo Service ConfighelloService=com.demo.HelloService


引入js:

<script language="JavaScript" src="js/prototype.js"></script><script language="JavaScript" src="js/buffalo.js"></script>


index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title><script language="JavaScript" src="js/prototype.js"></script><script language="JavaScript" src="js/buffalo.js"></script><script type="text/javascript">var endPoint="<%=request.getContextPath()%>/bfapp";function callFn(){var buffalo = new Buffalo(endPoint);buffalo.remoteCall("helloService.sayHi",["sang"], function(reply) {alert(reply.getResult());});}</script></head><body><button onclick="callFn();">test</button></body></html>


結果:



printf("Hello,world")與printf("Hello,world!\n")有什不同?

這個原因是由於 printf是行緩衝的(因為串連到了終端,/dev/ttys0,否則就是全緩衝的)。
fork的時候,父進程的io緩衝還沒有被清掉(也有可能是子進程,這個時候順序不確定。),所以 把父,子進程的內容一次輸出,就是一行的兩個 hello world。
當加了換行之後,printf是行緩衝的,所以在fork之後呢,會清掉一行的資料,就只有一個hello world出現了。

可以在fork之前加2秒的sleep看下,會看的很清楚。

參考unix進階編程 關於標準io和進程式控制制的章節。
 
hello,world

echo "hello,world!";
MessageBox.Show("hello,world!");
Console.Write("hello,world!");
AfxMessageBox("hello,world!");
cout<<"hello,world";
printf("hello,world");
system.out.println("hello,world");
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.