我被分配了一个用 J2ME(用于黑莓设备)制作的项目,该项目使用原始 asp 文件来查询客户的数据库。想法是将这个 J2ME 项目迁移到 Android。
问题是我还没有找到在我的项目中使用这些 asp 文件的方法(而且我不打算将这些文件更改为另一种语言,因为它们是很多文件),因为他们为此使用了 J2ME 类,而且我正在改造这个项目,但使用的是 android;asp 文件必须保持原样。
我会在原J2ME类中留下一些代码,asp名称是registerUser.asp,如果需要asp代码,我可以稍后贴出来。谢谢你。
HTTPConnections.java
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpConnection;
import org.xml.sax.SAXException;
public class HTTPConnections {
private static String URL_SERVER = "http://XX.XX.XXX.XXX";
private static String URL_BASE = "BB";
private static String URL_DIR = "BB";
private static String URL_REGISTER_USER = URL_SERVER+"/"+URL_BASE+"/"+URL_DIR+"/registerUser.asp";
public static boolean registerUser(String user, String password){
StreamConnection s = null;
PersistentStorage.database.setBD_AR__ID_TECNICO(0);
RegisterUserParser handler=null;
fin = getFinURL();
try {
s = (StreamConnection)Connector.open(URL_REGISTER_USER+"?u="+user+"&p="+password+";deviceside=true"+fin);
System.out.println(URL_REGISTER_USER+"?u="+user+"&p="+password+";deviceside=true"+";apn=web.iusacellgsm.mx");
HttpConnection httpConn = (HttpConnection)s;
int status = httpConn.getResponseCode();
System.out.println("El Status es: "+status);
PersistentStorage.database.setLog(PersistentStorage.database.getLog()+URL_REGISTER_USER+"?u=-"+user+"- p=-"+password+"- Status= "+status+"\n");
PersistentStorage.database.setLog(PersistentStorage.database.getLog()+"URL A LA BASE: "+URL_REGISTER_USER+"?u="+user+"&p="+password+"\n");
PersistentStorage.database.setLog(PersistentStorage.database.getLog()+"STATUS: "+status+"\n");
//Hector
PersistentStorage.database.setLog(PersistentStorage.database.getLog()+"El final del URL es: "+fin+"\n");
if (status == HttpConnection.HTTP_OK)
{
try {
InputStream input = s.openInputStream();
SAXParserImpl parser = new SAXParserImpl();
handler = new RegisterUserParser();
parser.parse(input, handler);
input.close();
} catch (SAXException e) {
//PersistentStorage.database.setLog(PersistentStorage.database.getLog()+"CATCH DEL SAX: "+e.getMessage()+"\n");
System.out.println("Error: 1 "+e.getMessage());
}
catch (IOException e){
System.out.println("Error: 500,000 "+e.getMessage());
handler = null;
}
PersistentStorage.database.setBD_AR__ID_TECNICO(handler.getIdTecnico());
}
s.close();
} catch (IOException e) {
PersistentStorage.database.setLog(PersistentStorage.database.getLog()+"CATCH 2: "+e.getMessage()+"\n");
System.err.println(e.toString());
System.out.println("Error: 2 "+e.getMessage());
}
if( handler!=null )
return true;
else
return false;
}
public static String getFinURL(){
String finURL = "", user ="", pass="";
String gSP = getServiceProvider();
if(gSP.equalsIgnoreCase("IUSACELL") && red.equalsIgnoreCase("CDMA")){
finURL = "";
}
else if(gSP.equalsIgnoreCase("IUSACELL") && !red.equalsIgnoreCase("CDMA")){
finURL=";apn=web.iusacellgsm.mx";
}
else if(gSP.equalsIgnoreCase("TELCEL GSM") && red.equalsIgnoreCase("GPRS")){
user=";TunnelAuthUsername=webgprs";
pass=";TunnelAuthPassword=webgprs2002";
finURL=";apn=internet.itelcel.com"+user+pass;
}
else if(gSP==null)
finURL = "Dio null";
else
finURL = "";
System.out.println("Mi URL es: "+finURL +" us: " + user+" pass: "+pass);
return finURL;
}
}