السلام عليكم
قمت بعمل برنامج للجوال يقوم يقوم بارسال بيانات حقلين هما اليوزر نيم والباسورد من الجوال الى صفحة php
والبرنامج شغال مية مية فقط مع ارسال البيانات باللغة الانجليزية
ولكن عند ادخال اسم مستخدم او باسورد باللغة العربية لا يتم ارسالهم الى صفحة البي اتش بي
لذالك ارجوا من الذي عنده كود بسيط ان يشرحه لنا ويعدل على الكود التالي _ ساضع الكود للفائدة -
كود j2me
اسم الملف (Network.java)
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
import java.util.*;
import java.lang.*;
public class Network extends MIDlet implements CommandListener
{
Display display;
Command exitCommand;
Command updateCommand;
Form screen;
public
TextField inputfield;
TextField inputfield2;
TextField outputfield;
StringItem aboutme = new StringItem("","");
InputStream in = null;
String url = new String();
public Network()
{
// Setup Display
display = Display.getDisplay(this);
exitCommand = new Command("اغلاق",Command.EXIT, 1);
updateCommand = new Command("دخول", Command.SCREEN,2);
inputfield= new TextField(" اسم المستخدم:", "", 256, TextField.ANY);
inputfield2= new TextField("كلمة السر :", "", 256, TextField.PASSWORD);
//String s=new String("arabic_string".getBytes(), "UTF-8");
outputfield= new TextField("الحاله:", "جاهز", 256, TextField.UNEDITABLE);
screen = new Form("تسجيل الدخول ");
screen.append(inputfield);
screen.append(inputfield2);
screen.append(outputfield);
screen.append(aboutme);
screen.addCommand(exitCommand);
screen.addCommand(updateCommand);
screen.setCommandListener(this);
}
public void startApp()
{
//Show the Window Form on the Screen
display.setCurrent(screen);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
}
public void update_action()
{
// Create a thread to actually connect to the webserver
Thread t = new Thread()
{
public void run()
{
//open connecttion
//,inputfield.getString(),inputfield2.getString()
try
{
outputfield.setString("جاري الاتصال ...");
url = generateGetUrl("http://h1.ripway.com/oneofmenf6/J2ME/j2me_php_test.php",inputfield.getString(),inputfield2.getString());
System.out.print("\n" + url + "\n");
if(updateSite(url)==1)outputfield.setString("تم التحديث");
else
outputfield.setString("فشل الدخوال. =(");
}
catch(IOException e)
{
outputfield.setString("فشل الاتصال. =(");
}
}
};
t.start();
}
public void commandAction(Command c, Displayable s)
{
if(c==updateCommand)
{
update_action();
}
if(c==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
//Function that formats the url string coding (IE %20 for spaces)
public String generateGetUrl(String url, String text , String text2)
{
String newUrl = new String();
StringBuffer c = new StringBuffer(text);
StringBuffer b = new StringBuffer(text2);
newUrl = url + "?text=" + c.toString() + "&text2=" + b.toString();
return newUrl.toString();
}
// This function connects to the site using the HTTP GET method
public int updateSite(String url) throws IOException
{
HttpConnection conn = null;
DataOutputStream out = null;
try
{
conn = (HttpConnection)Connector.open(url);
conn.setRequestMethod(HttpConnection.GET);
conn.setRequestProperty("Connection", "close");
if(conn.getResponseCode() == HttpConnection.HTTP_OK)
{
//We connected to the site
return 1;
}
else
{
//We didn't connect =(
return 0;
}
}
catch(IOException e)
{
System.out.print("فشل الاتصال بالسيرفر");
return 0;
}
}
}
كود صفحة البي اتش بي
أسم الملف(j2me_php_test.php)
<?
$text1 = $_GET["text"];
$text2 = $_GET["text2"];
$text = "username:".$text1."<br>"."pass:".$text2."<br>"."<br>";
$file = fopen("newText_test.html","a");
fwrite($file, $text);
fclose($file);
echo $text ;
?>
