想要做出類似Google Suggest的功能嗎?
這裡有一篇教學文章~以及作者所分享的程式碼~ Try it!
blog.Ring.idv.tw
In Ajax
2007-08-17 16:47:27 | Comments (1)
In Java
由於適逢需要利用Java連結Foxpro來操作一些資料庫~
所以找了一下資訊~這裡將利用透過ODBC的方式來連接~
所以我們必須先下載並安裝「Visual FoxPro ODBC Driver」,以便從「系統管理工具」>「資料來源ODBC」來設定~
基本設定方式
1.驅動程式請選「Microsoft Visual FoxPro Driver」
2.Data Source Name,請自定一個識別字串
3.Database type,如果你只有dbf檔案的話,請選「Free Table directory」
4.Path,請填你存放這些dbf檔案的路徑即可
設定之後便可測試一下:
import java.sql.*;
public class JDBCDemo
{
private PreparedStatement ps;
private ResultSet rs;
private Connection conn;
public JDBCDemo()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn = DriverManager.getConnection("jdbc:odbc:"+DataSourceName);
ps = conn.prepareStatement("select * from test");
rs = ps.executeQuery();
while(rs.next())
{
System.out.println(rs.getString(1));
}
} catch (Exception e)
{
System.out.print(e);
}
}
public static void main(String args[])
{
new JDBCDemo();
}
}
2007-08-17 00:55:14 | Add Comment
In Open Source, Java, Servlet
一般我們常見的HTML輸入型態(例如:text、radio、select…)都是使用「application/x-www-form-urlencoded」的編碼方式,但要傳送檔案至伺服端時,編碼方式則是要仰賴「multipart/form-data」,由於兩者的編碼方式不同,所以這裡提供一個「FileUpload」的小範例~
必要的package如下:
HTML
<%@page language="java" contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>檔案上傳</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<b>檔案上傳</b></font></p>
<form name="UploadForm" enctype="multipart/form-data" method="post" action="fileupload.dan">
<input type="file" name="File1" size="20" maxlength="20"> <br>
<input type="text" name="File2" size="20" maxlength="20"> <br>
<input type="submit"value="上傳">
</form>
</body>
</html>
Servlet
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class FileUpload extends HttpServlet
{
private String base;
public void init(ServletConfig sc) throws ServletException
{
ServletContext sco = sc.getServletContext();
base = sco.getRealPath("/");
}
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
boolean isMultipart = ServletFileUpload.isMultipartContent(req);
try
{
if(isMultipart)
{
DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096);
factory.setRepository(new File(base+"temp"));
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(10000000);
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
while(iter.hasNext())
{
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString();
System.out.println("name:"+name+" value:"+value);
} else {
String fieldName = item.getFieldName();
String fileName = item.getName();
String contentType = item.getContentType();
boolean isInMemory = item.isInMemory();
long sizeInBytes = item.getSize();
System.out.println("fieldName:"+fieldName+" fileName:"+fileName);
File to = new File(base+"upload",fileName);
item.write(to);
}
}
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
2007-08-10 14:52:00 | Comments (2)
上圖是SWF and FLV File Format Specification (Version 9)所描述的DoABC Tag,從圖上可以知道此Tag裡頭包含了「Flags」和「ABCData」,然而真正在剖析時,似乎並不是那麼一回事~
Flash CS3(AS3)
Flex Showcase 1(已經過解壓處理)
Flex Showcase 2(已經過解壓處理)
上述三張圖的「紅色」部份是DoABC Tag所包含的「Header」、「Length」和「Flags」,而「藍色」部份則是AS3 bytecode的「minor_version」和「major_version」,重點在於「綠色」部份卻沒有任何文件的說明,然而從Flex Showcase 1,2卻可以發現他所包含的資訊卻是「frame1」的字元,所以此部份的格式型態應該屬於「String」,也就是說在「Flags」之後緊接著的是「frame編號的資訊」,最後才是「ABCData」,但這部份仍屬於筆者的猜測。
2007-08-03 17:19:53 | Add Comment
ActionScript Virtual Machine 2 (AVM2) Overview這份文件中的第66頁,描述此「greaterequals」instruction,但其底下的「Format」、「Forms」是有錯誤的~
如下所示:
錯誤
[Format]:greaterthan [Forms]:greaterthan = 175 (0xaf)
更正
[Format]:greaterequals [Forms]:greaterequals = 176 (0xb0)
參考文件:AVM2 instructions
2007-08-02 18:21:27 | Add Comment