//ConnectASP.ASP <%@LANGUAGE=VBScript%> <% strDBLocation=Server.Mappath("/database/J2METest.mdb"); strConnectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source="+strDBLocation; var cnn=Server.CreateObject("ADODB.Connection"); cnn.Open(strConnectionString); rs=Server.CreateObject("ADODB.Recordset"); ip=Request.ServerVariables("REMOTE_ADDR"); message=Request.QueryString("message"); rs.ActiveConnection=cnn; rs.CursorType=1; rs.LockType=2; rs.Source="Message"; rs.Open(); rs.AddNew(); rs("Message")=message; rs("IP")=ip; rs("Date")=(new Date()).getVarDate(); rs.Update(); rs.Close(); cnn.Close(); Response.Write("The message writed successfully.\n"); %>
//ConnectASP.java import javax.microedition.midlet.*; import javax.miceoedition.io.*; import Java.io.*; public class ConnectASP extends MIDlet{ public void startApp(){ try{ testASP();測試ASP連接 }catch(IOException e){ System.out.println("error"); } notifyDestroyed(); } void testASP()throws IOException{ try{ String uri="http://localhost/asp/ConnectASP.ASP?message=Hello+J2ME!"; HttpConnection conn=(HttpConnection)Connector.open(uri); InputStream in=conn.openInputStream(); int ch; while((ch=in.read()!=-1){ System.out.print((char)ch); } in.close(); conn.close(); }catch(ConnectionNotFoundException e){ System.out.println("Http could not be opened"); } } public void pauseApp(){} public void destroyApp(boolean unconditional){} }