الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

الرد من السيرفر كصورة الى شاشة الموبايل

بدأه lady-A في 11 يناير 2009 · 13 رد · 1,852 مشاهدة · في JavaME
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكــم ورحمـة الله وبركاتــه

احنا طالبات تخرج

مشروعنا باختصار عبارة عن برنامج على الجوال يقوم بتوجيه الطالبة آليا للقاعة المحددة

بالإضافة لخدمات أخرى

استخدمنا النت بينز لكتابة كود الجي تو مي

والسيرفليت للتعامل مع قاعدة البيانات الموجودة على الـ

MY SQL

عندنا عدة أسئلة أتمنى تساعدونا فيها

وربي يفرج عنكم كرب الدنيا والآخرة

1-

السيرفليت لما يتصل بقاعدة لبيانات يعبي البيانات في

List

عشان يقدر يتعامل معاها

بس الـ

List

تنحفظ في الجوال .. فهل هذا الشيء صحيح أو إنه لازم يجيبها كل مرة من السيرفر ؟؟؟

2-

هل يكون عندي سيرفليت واحد احط فيه كل طلباتي من قاعدة البيانات أو لكل طلب سيرفليت منفصل ؟؟؟

وممكن لو سمحتوا تشرحوا لي كيف ارسل باراميتر للسيرفليت ، يعملله معالجة ثم يرجع لي الإجابة ؟؟

3-

برمجة المسار على الجوال راح تكون على أساس اختيار الـ

shortest path

واحتمال نشتغل على الـ

aunt algorithm

فهل تنصحونا نخلي البرمجة على الجوال .. يعني هل حيقدر يتحملها ؟؟

أو نخليها على السيرفليت ويرسلها لنا كـ صورة ؟؟

4-

في السيرفليت .. تطلع لي هذي المسج أحيانا

com.mysql.jdbc.Driver

بس ماتطلع على جهاز صحبتي مع اننا شغالين على نفس الكود .. وين المشكلة ؟؟؟

هذا جزء من كودنا يشرح طريقة التعامل مع القاعة


* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;
import javax.microedition.rms.*;
//import org.netbeans.microedition.lcdui.SplashScreen;


public class Midlet extends MIDlet implements CommandListener {
Display display = null;
private Form form = null;
Form form2 = null;
private TextField location ,floor;
String str = null;
private List list;
private List Room;
private List list3;
//private SplashScreen splashScreen;
private Form First;
private Form formsh;
private ChoiceGroup choiceGroup;
private int replyIndex;
private ChoiceGroup chGroup,cGroup;
private int rpyIndex,rpIndex; // Index of "reply" in choice group
private int choiceGroupIndex;
private Form Help1;
private Form HelpRoom;
private Command okCommand;
private Command exitCommand;
private Command itemCommand;
private Command okCommand1;
private Command backCommand;
private Command Open1;
private Command HomePage;
private Command Help;
private Command schedule;
private Command Exit;
private Font font1;
private Image image1;
private Font font2;

// private Command show;

String url = "http://localhost:8080/WebApplication1/NewServlet";
//Command backCommand12 = new Command("Back", Command.BACK, 0);
Command backCommand1 = new Command("OK", Command.OK, 0);
Command submitCommand = new Command("Submit", Command.OK, 2);
Command exitCommand12 = new Command("Exit", Command.STOP, 3);

private Test test;
private Command show;

//public Midlet() {}




public Midlet()
{
display = Display.getDisplay(this);
// Create an exclusive (radio) choice group
choiceGroup = new ChoiceGroup("Selected one of a Colleges:", Choice.EXCLUSIVE);

// Append options, with no associated images
replyIndex = choiceGroup.append("Faculty of Computer and Information Technology", null);

choiceGroup.append("College of Home Economics", null);
choiceGroup.append("Faculty of Economics and management", null);
choiceGroup.append("College of Arts and Human Sciences", null);

// Set "reply" as the default/selected option
choiceGroup.setSelectedIndex(replyIndex, true);

exitCommand = new Command("Exit", Command.EXIT, 1);
okCommand = new Command("View", Command.SCREEN,2);
show= new Command("display the guidance", Command.SCREEN, 3);
schedule=new Command("schedule of study", Command.SCREEN, 3);
Open1 = new Command("open", Command.OK, 0);
HomePage = new Command("HomeBage", Command.OK, 0);
Help = new Command("Help", Command.OK, 2);
backCommand1 = new Command("Back", Command.BACK, 0);

//text field
floor= new TextField("No. Floor:", "", 30, TextField.ANY);
location = new TextField("The nearest place", "", 30, TextField.ANY);


// Create Form, add components, listen for events
First = new Form("");
choiceGroupIndex = First.append(choiceGroup);
First.addCommand( exitCommand);
First.addCommand(okCommand);
First.setCommandListener(this);
list3 = new List("Employee List", Choice.IMPLICIT);
list3.append(" Room", null);
list3.append(" Faculty members ", null);
list3.append(" Administrative Affairs", null);
list3.append(" Else", null);
list3.addCommand(backCommand1);
list3.addCommand( Open1);
list3.addCommand(HomePage);
list3.addCommand(Help);
list3.addCommand( exitCommand);
list3.setCommandListener(this);

Room = new List("Room Choice", Choice.IMPLICIT);
Room.append("Search for Specific Class", null);
Room.append("Search for empty Class", null);
Room.addCommand(backCommand1);
Room.addCommand( Open1);
Room.addCommand(HomePage);
Room.addCommand(Help);
Room.addCommand( exitCommand);
Room.setCommandListener(this);
form = new Form("");
form.append("Select your location");
form.append(floor);
form.append(location);
form.addCommand(backCommand1);
form.addCommand(show);
form.addCommand(schedule);
form.addCommand(exitCommand );
form.addCommand(HomePage );
form.setCommandListener(this);
//=======================================================
//=======================================================
chGroup = new ChoiceGroup("Selected one of a Colleges:", Choice.EXCLUSIVE);

rpyIndex = chGroup.append("Saturday", null);

chGroup.append("Sunday", null);
chGroup.append("Monday ", null);
chGroup.append("Tuesday ", null);
chGroup.append("Wednesday", null);

// Set "reply" as the default/selected option
chGroup.setSelectedIndex(rpyIndex, true);
//======================================================
//======================================================
cGroup = new ChoiceGroup("Selected one of a Colleges:", Choice.EXCLUSIVE);

rpIndex = cGroup.append("Saturday", null);

cGroup.append("Sunday", null);
cGroup.append("Monday ", null);
cGroup.append("Tuesday ", null);
cGroup.append("Wednesday", null);

// Set "reply" as the default/selected option
cGroup.setSelectedIndex(rpIndex, true);
//=========================================================
//=========================================================
form2 = new Form("");
choiceGroupIndex = form2.append(chGroup);
form2.addCommand(backCommand1);
form2.addCommand(show);
form2.addCommand(schedule);
form2.addCommand(exitCommand );
form2.addCommand(HomePage );
form2.setCommandListener(this);
//===================================================
formsh = new Form("");
choiceGroupIndex = formsh.append(cGroup);
formsh.addCommand(backCommand1);
formsh.addCommand(show);
formsh.addCommand(schedule);
formsh.addCommand(exitCommand );
formsh.addCommand(HomePage );
formsh.setCommandListener(this);


}

public void startApp() throws MIDletStateChangeException {
display.setCurrent(First);

}
public void pauseApp() {}

public void destroyApp(boolean unconditional) {}

class Test implements Runnable {
Midlet midlet;
private Display display;
String text;

public Test(Midlet midlet) {
this.midlet = midlet;
display = Display.getDisplay(midlet);
}

public void start() {
Thread t = new Thread(this);
t.start();
}

public void run() {
StringBuffer sb = new StringBuffer();
char[] s=new char[8];
try {
HttpConnection c = (HttpConnection) Connector.open(url);
c.setRequestProperty(
"User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

c.setRequestProperty("Content-Language","en-US");
//c.setRequestMethod(HttpConnection.POST);

// DataOutputStream os =
// (DataOutputStream)c.openDataOutputStream();

// os.writeUTF(text.trim());
// os.flush();
// os.close();

// Get the response from the servlet page.
DataInputStream is =(DataInputStream)c.openDataInputStream();
// is = c.openInputStream();
int ch;
String m="";
int x;
// sb = new StringBuffer();
list = new List("Employee List", Choice.IMPLICIT);
//show = new Command("Show", Command.OK, 1);
while ((ch = is.read()) != -1) {
sb.append((char)ch);
if ((char)ch == '\n')
{ //break;
//sb.toString();
x=sb.length();
list.append(sb.toString(), null);
sb.delete(0, x);


}

//display = Display.getDisplay(this);

}

// showAlert(sb.toString());
is.close();
c.close();
list.addCommand(backCommand1);
list.addCommand(show);
list.addCommand(schedule);
list.addCommand(exitCommand );
list.addCommand(HomePage );

display.setCurrent(list);
list.setCommandListener(midlet);
} catch (Exception e) {
//showAlert(e.getMessage());
}
}
/* This method takes input from user like text and pass
to servlet */
public void getServlet(String text) {
this.text = text;
}

/* Display Error On screen*/
private void showAlert(String err) {
Alert a = new Alert("");
a.setString(err);
a.setTimeout(Alert.FOREVER);
display.setCurrent(a);
}
}
public void commandAction(Command c, Displayable d) {
if (d == First){ if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();
} else if (c == backCommand1) {
display.setCurrent(form);
} else if (c == okCommand) {
display.setCurrent(list3);

}}
else if (d == list3){
if (c == Open1){
display.setCurrent(Room);
//str = tb.getString();

}else if (c == backCommand1) {
display.setCurrent(First);}

else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}
else if (c == List.SELECT_COMMAND){
String roomch=list3.getString(list3.getSelectedIndex());
if(roomch != null)
{
if(roomch.equals(" Room")){
display.setCurrent(Room);
}

}
}

}
else if (d == Room){
if (c == Open1){

//str = tb.getString();
test = new Test(this);
test.start();
test.getServlet(str);
}
else if (c == backCommand1) {
display.setCurrent(list3);}
else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}
else if (c == List.SELECT_COMMAND){
String roomch=Room.getString(Room.getSelectedIndex());
if(roomch != null)
{
if(roomch.equals("Search for Specific Class")){
test = new Test(this);
test.start();
test.getServlet(str);
}
if(roomch.equals("Search for empty Class")){
display.setCurrent(formsh);
/*test = new Test(this);
test.start();
test.getServlet(str);*/
}

}
}

}
else if (d == list){
if (c == show){
display.setCurrent(form);
//str = tb.getString();

}else if (c == backCommand1) {
display.setCurrent(Room);}
else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}
else if (c == schedule) {
display.setCurrent(form2);}

}
else if (d == form){
if (c == show){
display.setCurrent(form);
//str = tb.getString();

}else if (c == backCommand1) {
display.setCurrent(list);}
else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}
else if (c == schedule) {
display.setCurrent(form2);}

}
else if (d == form2){
if (c == show){
display.setCurrent(form);
//str = tb.getString();

}else if (c == backCommand1) {
display.setCurrent(list);}
else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}

}
else if (d == formsh){
if (c == show){
display.setCurrent(form);
//str = tb.getString();

}else if (c == backCommand1) {
display.setCurrent(Room);}
else if (c == exitCommand) {
destroyApp(true);
notifyDestroyed();}

}
}
}
/*

#2

السلام عليكم

1- بالطبع في كل مرة من طلب قاعدة البيانات من السيرفلت سوف يقوم بالرد بقائمة جديدة list . :)

2- اما بالنسبة للسيرفلت فلا تحتاج اكثر من سيرفلت الا اذا اردتي التنظيم و الترتيب .

3- بالنسبة لنوع الرد من السيرفر كصورة سوف يكون ثقيل ، و انا خطرت في بالي ان يعيد نقاط يقوم الموبايل بالربط بينها .

4- اما بالنسبة للمسج فمن المحتمل لن جهازك لا يحتوي على MySQl .

#3

شكراا جزيلا لك اخي على الرد

ولكن لاتزال لدينا بعض الاستفسارات

بالنسبه لرسم المسار على الخريطة هل لو اننا اخذنا النقاط من السيرفر

وعملنا الكود في ال j2me هل هذا يكون سهل على الj2me

اي انوا ماراح يكون كبير عليه .

#4

هذه ميدليت لكي تعرض صورة...

طبعا يجب ان تراعي حجم الصورة من مصدرها

package ws.ramy;

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;

public class ImageMidletServlet extends MIDlet implements CommandListener
{
	Display display = null;
	Form form = null;
	String url = "http://207.210.96.98:8180/tomcat.gif";
	Command backCommand = new Command("Back", Command.BACK, 0);
	Command submitCommand = new Command("Submit", Command.OK, 2);
	Command exitCommand = new Command("Exit", Command.STOP, 3);
	private Test test;

	public ImageMidletServlet() {}

	public void startApp() throws MIDletStateChangeException
	{
		display = Display.getDisplay(this);
		form = new Form("Show Image");
		form.addCommand(submitCommand);
		form.addCommand(exitCommand);
		form.setCommandListener(this);
		display.setCurrent(form);
	}

	public void pauseApp() {}

	public void destroyApp(boolean unconditional) {}

	public void commandAction(Command c, Displayable d)
	{
		if (c == exitCommand)
		{
			destroyApp(true);
			notifyDestroyed();
		}
		else if (c == backCommand)
		{
			display.setCurrent(form);
		}
		else if (c == submitCommand)
		{
			test  = new Test(this);
			test.start();
		}
	}


	class Test implements Runnable
	{
		ImageMidletServlet midlet;
		private Display display;

		public Test(ImageMidletServlet midlet)
		{
			this.midlet = midlet;
			display = Display.getDisplay(midlet);
		}

		public void start()
		{
			Thread t = new Thread(this);
			t.start();
		}

		public void run()
		{
			DataInputStream is = null;
			StringBuffer sb = new StringBuffer();
			Image img= null;
			try
			{
				HttpConnection c = (HttpConnection) Connector.open(url);
				int len = (int)c.getLength();

				if (len > 0)
				{
					is = c.openDataInputStream();
					byte[] data = new byte[len];
					is.readFully(data);
					img = Image.createImage(data, 0, len);
					Form f = new Form("Image");
					ImageItem imgItem = new ImageItem("", img,
					  ImageItem.LAYOUT_NEWLINE_AFTER |
					  ImageItem.LAYOUT_CENTER, null);

					f.append(imgItem);
					display.setCurrent(f);
				}
				else
				{
					showAlert("length is null");
				}
				is.close();
				c.close();
			}
			catch (Exception e)
			{
				e.printStackTrace();
				showAlert(e.getMessage());
			}
		}
		/* Display Error On screen*/
		private void showAlert(String err)
		{
			Alert a = new Alert("");
			a.setString(err);
			a.setTimeout(Alert.FOREVER);
			display.setCurrent(a);
		}
	};
}

اظن ان الكود واضح... و على اي حال لا تترد في السؤال عن اي مقطع او سطر لم تفهمه

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#5

على فكرة الموضوع مخالف جدا لقوانين المشاركة سوف اقوم بتعديل العنوان هذه المرة فقط على شرط عدم تكرار المخالفة ( العنوان لا يناسب ولا يوضح المحتوى)

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#6

عذراا

لكن ماكنا نعرف اش نضع عنوان الموضوع لانه كان عندنا كذا استفسار وليس استفسار واحد

ولكن أؤكد لك بانها لن تتكرر

شكراا لك اخي على المساعدة

لكن لدينا بعض الاستفسارات نرجو منكم الافادة

في الservlet لم نجد الطريقه التي نرسل بها طلب وعلى اساسها يعمل الاستعلام المطلوب من الdata base

فهل يكون صحيح ان نضع لكل استعلام servlet علماا انو عدد الاستعلامات كبير جدا (بعدد القاعات والاستاذات)

هذا هوا كود ال servlet

import java.io.*;
import java.util.Enumeration;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.net.*;
public class NewServlet extends HttpServlet{
Connection theConnection;
private ServletConfig config;


public void init(ServletConfig config)
throws ServletException{
this.config=config;
}

public void service (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {




res.setContentType("text/html");

PrintWriter out = res.getWriter();



try{


//Loading Sun's JDBC ODBC Driver
Class.forName("com.mysql.jdbc.Driver");


//Connect to emaildb Data source
theConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mare_nav", "root", "");


Statement theStatement=theConnection.createStatement();

ResultSet theResult=theStatement.executeQuery("SELECT buil_id from rooms "); //Select all records from emaillists table.

//Fetch all the records and print in table
while(theResult.next()){

out.println( theResult.getString(1) );
//out.println(theResult.getString(2) );





}

theResult.close();//Close the result set

theStatement.close();//Close statement

theConnection.close(); //Close database Connection

}catch(Exception e){

out.println(e.getMessage());//Print trapped error.

}


}

public void destroy(){

}

}

ولكم منا جزيل الشكر

#7

لا من المستحيل ان تقومو بتطوير سيرفلت لكل استعلام!!!

يجب ان يكون هناك مثلا صفحة JSP او سيرفلت المهم ان تعمل بحسب البرامتر المرر من برنامج الموبايل

مثلا

http://207.210.96.98:8180/sms.jsp?user=ramy

هذه الصفحة تعيد نفس البرامتر الممر

في صفحتكم حسب البرامتر سوف تقوم الصفحة بتنفيذ الاستعلام المحدد و بعدها تعيد القيمة المطلوبة

HttpConnection c = null;
InputStream iss = null;
StringBuffer sb = new StringBuffer();
try {
  c = (HttpConnection)Connector.open( "http://207.210.96.98:8180/sms.jsp?user=hihih", Connector.READ_WRITE, true);
  c.setRequestMethod(HttpConnection.GET); //default
  iss = c.openInputStream(); 
  int ch = 0;
  for(int ccnt=0; ccnt < 150; ccnt++) { 
	ch = iss.read();
	if (ch == -1){
	  break;
	}
	sb.append((char)ch)
textField.setString(sb.toString());
  }
}
catch (IOException x){
	x.printStackTrace();
}
finally{
	 try	 {
	   iss.close();
		  c.close();
	 } catch (IOException x){
		  x.printStackTrace();
	 }
}
System.out.println(sb.toString());

}

هذا الكود تستطيع من خلاله ارسال البرامترات بطريقة GET الى صفحة JSP

طبعا يجب ان تكون textField معرفة من قبل في برنامجكم الموبايل

مع تمنياتي بالتوفيق

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#8

انا جداااا آسفه لكني لم افهم ما تفضلت به

هل كنت تقصد ان ارسل برامتر الى صغحة jsp وهي ترسل الطلب لل servlet

او ان التعامل فقط بين المبايل و servlet

احنا مشكلتنا كانت في كود ال servlet ما عرفنا كيف نعرف البرامتر الممرر لها من المبايل

هذا كود المبايل الذي حاولنا فيه تمررير برامتر الى ال servlet واستقبال الرد في list

public void run() {
			StringBuffer sb = new StringBuffer();

			try {

				HttpConnection c = (HttpConnection) Connector.open(url+str,Connector.READ_WRITE, true);
				c.setRequestProperty(
				  "User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

				c.setRequestProperty("Content-Language","en-US");
			   c.setRequestMethod(HttpConnection.POST);

				DataOutputStream os =
					   (DataOutputStream)c.openDataOutputStream();

			   os.writeUTF(str.trim());

			   os.flush();
			   os.close();

				// Get the response from the servlet page.
				DataInputStream is =(DataInputStream)c.openDataInputStream();
				c.setRequestMethod(HttpConnection.GET); 
			 //   is = c.openInputStream();
				int ch;
				int x;
			  //  sb = new StringBuffer();
list = new List("Room List", Choice.IMPLICIT);
				while ((ch = is.read()) != -1)  {
					sb.append((char)ch);
					if ((char)ch == '\n')
					{	  
	x=sb.length();
	list.append(sb.toString(), null);
	sb.delete(0, x);


   }
  }
				is.close();
				c.close();
 list.addCommand(backCommand1);
 list.addCommand(show);
 list.addCommand(schedule);
 list.addCommand(exitCommand );
 list.addCommand(HomePage );

 display.setCurrent(list);
  list.setCommandListener(midlet);
			} catch (Exception e) {
				showAlert(e.getMessage());
			}
		}

بس ماعرفنا نقرا ال str المرسل في servlet

وشكراا جزيلا لك على كل ماتفضلت به

#9

السلام عليكــم ورحمـة الله وبركاتــه

اخي او اختي

عليك الانتباه ان سعة الheap memory في الموبايل قد لا تتعدى 1 ميغا

و عند تحميل الصور انت تستهلك امرين

1- heap memory

2- حجم البيانات المرسلة كبيرة بين السيرفر و الموبايل ( انا اعرف انك تقول ليست بالكثير )

و انا افضل تراسل النقاط و رسمها باستخدام الكنفاس.

و هذا موضوع ربط الموبايل بسيرفلت و قاعدة بيانات :

ربط الموبايل بقواعد البيانات.

#10

لا اعرف اذا كان سؤالك بسيط لهل الدرجة و لكن لكي تاخذ قيمة البارامتر نستعمل التعليمةالتالية

String user =request.getParameter("user")

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#11

شكراا جزيلا لكم جميعاا

ولكن حاولت بكل الطرق ولم اصل الى نتيجه

اعتذر لكثر اسئلتي ولكني اطمع في كرمكم

هذا الكود الي حاولت في بنفس الطريقه التي وضحتها في الرابط

ولكن دون جدوى

هذا كودj2me

import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Vector;
import javax.microedition.rms.*;
//import org.netbeans.microedition.lcdui.SplashScreen;


public class Midlet extends MIDlet implements CommandListener {
  Display display = null;
int m=0;
  private Form form,form2,First,formsh,F1,F2,F3 = null;
  //Form form2 = null;
  private TextField location ,floor,loc,f,lca,fl;
  String str = null;
  String sst="xx";
  private List list;
  private List Room;
  private List list3,list4;
  //private SplashScreen splashScreen;
  //private Form First;
  //private Form formsh;
  private ChoiceGroup choiceGroup;
  private int replyIndex;
  private ChoiceGroup chGroup,cGroup;
  private int rpyIndex,rpIndex;  // Index of "reply" in choice group
  private int choiceGroupIndex;
  private Form Help1;
  private Form HelpRoom;
  private Form noOFof;
  private Command okCommand;
  private Command exitCommand;
  private Command itemCommand;
  private Command okCommand1;
  private Command backCommand1;
  private Command Open1;
  private Command noOfof;
  private Command HomePage;
  private Command Help;
  private Command schedule;
  private Command Exit;
  private Font font1;
  private Image image1;
  private Font font2;

	   // private Command show;

	String url = "http://localhost:8080/WebApplication1/NS1";
	//Command backCommand12 = new Command("Back", Command.BACK, 0);

	private Test test;
	private Command show;

	//public Midlet() {}




  public Midlet()
  {

	display = Display.getDisplay(this);
	// Create an exclusive (radio) choice group
   choiceGroup = new ChoiceGroup("Selected one of a Colleges:", Choice.EXCLUSIVE);

	// Append options, with no associated images
	replyIndex = choiceGroup.append("Faculty of Computer and Information Technology", null);

   choiceGroup.append("College of Home Economics", null);
   choiceGroup.append("Faculty of Economics and management", null);
   choiceGroup.append("College of Arts and Human Sciences", null);

	// Set "reply" as the default/selected option
	choiceGroup.setSelectedIndex(replyIndex, true);

 //=========================================================
//==========================================================

	exitCommand = new Command("Exit", Command.EXIT, 1);
	okCommand = new Command("View", Command.SCREEN,2);
	noOfof = new Command("phone number", Command.SCREEN,2);
	show= new Command("view Path", Command.SCREEN, 3);
	schedule=new Command("schedule of study", Command.SCREEN, 3);
	Open1 = new Command("open", Command.ITEM, 0);
	HomePage = new Command("HomeBage", Command.OK, 0);
	Help = new Command("Help", Command.OK, 2);
	backCommand1 = new Command("Back", Command.BACK, 0);

 //=========================================================
//==========================================================

	//text field
	floor= new TextField(" Floor .No:", "", 30, TextField.ANY);
	location = new TextField("The nearest place", "", 30, TextField.ANY);
	fl= new TextField(" Floor .No:", "", 30, TextField.ANY);
	loc = new TextField("The closest place", "", 30, TextField.ANY);
	f= new TextField(" Floor .No:", "", 30, TextField.ANY);
	lca = new TextField("The closest place", "", 30, TextField.ANY);

 //=========================================================
//==========================================================

	// Create Form, add components, listen for events
  First = new Form("");
  choiceGroupIndex = First.append(choiceGroup);
  First.addCommand( exitCommand);
  First.addCommand(okCommand);
  First.setCommandListener(this);

 //=========================================================
//==========================================================

 list4 = new List(" List", Choice.IMPLICIT);
 list4.append("	 agent of college", null);
 list4.append("	 Educational Affairs ", null);
 list4.append("	 the high Studies", null);
 list4.append( "	Deanship of Distance Learning", null);
 list4.addCommand(backCommand1);
 list4.addCommand( show);
 list4.addCommand( noOfof);
 list4.addCommand(HomePage);
 list4.addCommand(Help);
 list4.addCommand( exitCommand);
 list4.setCommandListener(this);

 //=========================================================
//==========================================================

 list3 = new List(" List", Choice.IMPLICIT);
 list3.append("	 Room", null);
 list3.append("	 Faculty members ", null);
 list3.append("	 Administrative Affairs", null);
 list3.append("	 Else", null);
 list3.addCommand(backCommand1);
 list3.addCommand( Open1);
 list3.addCommand(HomePage);
 list3.addCommand(Help);
 list3.addCommand( exitCommand);
 list3.setCommandListener(this);

 //=========================================================
//==========================================================

  Room = new List("Room Choice", Choice.IMPLICIT);
  Room.append("Search for Specific Class", null);
  Room.append("Search for empty Class", null);
  Room.addCommand(backCommand1);
  Room.addCommand( Open1);
  Room.addCommand(HomePage);
  Room.addCommand(Help);
  Room.addCommand( exitCommand);
  Room.setCommandListener(this);

 //=========================================================
//==========================================================

 form = new Form("");
 form.append("Select your location");
 form.append(floor);
 form.append(location);
 form.addCommand(backCommand1);
 form.addCommand(show);
 form.addCommand(exitCommand );
 form.addCommand(HomePage );
 form.setCommandListener(this);

//=======================================================
//=======================================================

chGroup = new ChoiceGroup("Select day:", Choice.EXCLUSIVE);

rpyIndex = chGroup.append("Saturday", null);

	chGroup.append("Sunday", null);
	chGroup.append("Monday ", null);
	chGroup.append("Tuesday ", null);
	chGroup.append("Wednesday", null);

	// Set "reply" as the default/selected option
	chGroup.setSelectedIndex(rpyIndex, true);

	//======================================================
	//======================================================

	cGroup = new ChoiceGroup("Select day:", Choice.EXCLUSIVE);

   rpIndex = cGroup.append("Saturday", null);

	cGroup.append("Sunday", null);
	cGroup.append("Monday ", null);
	cGroup.append("Tuesday ", null);
	cGroup.append("Wednesday", null);

	// Set "reply" as the default/selected option
	cGroup.setSelectedIndex(rpIndex, true);

 //=========================================================
 //=========================================================
 form2 = new Form("");
	choiceGroupIndex = form2.append(chGroup);
 form2.addCommand(backCommand1);
 form2.addCommand(show);

 form2.addCommand(exitCommand );
 form2.addCommand(HomePage );
 form2.setCommandListener(this);

 //=========================================================
//==========================================================

 formsh = new Form("");
	choiceGroupIndex = formsh.append(cGroup);
 formsh.addCommand(backCommand1);
 formsh.addCommand(show);
 formsh.addCommand(schedule);
 formsh.addCommand(exitCommand );
 formsh.addCommand(HomePage );
 formsh.setCommandListener(this);

 //=======================================================
 //=======================================================

 noOFof=new Form("");
 noOFof.addCommand(backCommand1);
 noOFof.addCommand(exitCommand );
 noOFof.addCommand(HomePage );
 noOFof.setCommandListener(this);

 //========================================================
//=========================================================

 F1 = new Form("");
 F1.append("Select your location");
 F1.append(fl);
 F1.append(loc);
 F1.addCommand(backCommand1);
 F1.addCommand(show);
 F1.addCommand(exitCommand );
 F1.addCommand(HomePage );
 F1.setCommandListener(this);


  }

	public void startApp() throws MIDletStateChangeException {
	   display.setCurrent(First);

	}
public void pauseApp() {}

	public void destroyApp(boolean unconditional) {}

   public class Test implements Runnable {
		Midlet midlet;
		private Display display;
		String text;

		public Test(Midlet midlet) {
			this.midlet = midlet;
			display = Display.getDisplay(midlet);
		}

		public void start() {
			Thread t = new Thread(this);
			t.start();
		}

		public void run() {
			StringBuffer sb = new StringBuffer();

			try {

				HttpConnection c = (HttpConnection) Connector.open(url);
				c.setRequestProperty(
				  "User-Agent","Profile/MIDP-1.0, Configuration/CLDC-1.0");

				c.setRequestProperty("Content-Language","en-US");
			   c.setRequestMethod(HttpConnection.POST);

				DataOutputStream os =
					   (DataOutputStream)c.openDataOutputStream();

			   os.writeUTF(text.trim());

			   os.flush();
			   os.close();

				// Get the response from the servlet page.
				DataInputStream is =(DataInputStream)c.openDataInputStream();

			 //   is = c.openInputStream();
				int ch;
				int x;
			  //  sb = new StringBuffer();
list = new List("Room List", Choice.IMPLICIT);
				while ((ch = is.read()) != -1)  {
					sb.append((char)ch);
					if ((char)ch == '\n')
					{	  
	x=sb.length();
	list.append(sb.toString(), null);
	sb.delete(0, x);


   }
  }
				is.close();
				c.close();
 list.addCommand(backCommand1);
 list.addCommand(show);
 list.addCommand(schedule);
 list.addCommand(exitCommand );
 list.addCommand(HomePage );

 display.setCurrent(list);
  list.setCommandListener(midlet);
			} catch (Exception e) {
				showAlert(e.getMessage());
			}
		}
				/* This method takes input from user like text and pass
				to servlet */
		public void getServlet(String text) {
			this.text = text;
		}

		/* Display Error On screen*/
		private void showAlert(String err) {
			Alert a = new Alert("");
			a.setString(err);
			a.setTimeout(Alert.FOREVER);
			display.setCurrent(a);
		}
	}
	 public void commandAction(Command c, Displayable d) {
	   if (d == First){ if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();
		} else if (c == backCommand1) {
			display.setCurrent(form);
		} else if (c == okCommand) {
			display.setCurrent(list3);

		}}
else if (d == list3){
	if (c == Open1 && (list3.getSelectedIndex()==0)){
		 display.setCurrent(Room);
	 //str = tb.getString();

		}
	else if (c == Open1 && (list3.getSelectedIndex()==2)){
		 display.setCurrent(list4);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(First);}

	else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	else if (c == List.SELECT_COMMAND){
	String roomch=list3.getString(list3.getSelectedIndex());
	if(roomch != null)
	{
		if(roomch.equals("	 Room")){
			display.setCurrent(Room);
		}
		else if(roomch.equals("	 Administrative Affairs")){
			display.setCurrent(list4);
		}

	}
	}

}
	   else if (d == Room){
	if (c == Open1){
 str="1";
	 //str = tb.getString();
		   test  = new Test(this);
			test.start();
			test.getServlet(str);
		}
	else if (c == backCommand1) {
			display.setCurrent(list3);}
	else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	 else if (c == List.SELECT_COMMAND){
	String roomch=Room.getString(Room.getSelectedIndex());
	if(roomch != null)
	{
		if(roomch.equals("Search for Specific Class")){
		   str="1";
			 test  = new Test(this);
			test.start();
		  test.getServlet(str);
		}
		if(roomch.equals("Search for empty Class")){
			 str="1";
			 test  = new Test(this);
			test.start();
			test.getServlet(str);
		}

	}
	}

}
else if (d == list){
	for(int i=0;i<=list.size();i++)
	{
	if (c == show){
		 display.setCurrent(form);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(Room);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	else if (c == schedule) {
			display.setCurrent(form2);}
	}
	   }
	   else if (d == form){
	if (c == show){
		 display.setCurrent(form);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(list);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	else if (c == schedule) {
			display.setCurrent(form2);}

	   }
	   else if (d == form2){
	if (c == show){
		 display.setCurrent(form);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(list);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}

	   }
	   else if (d == formsh){
	if (c == show){
		 display.setCurrent(form);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(Room);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}

	   }
	   else if (d == list4){
	if (c == show){
		  display.setCurrent(F1);
		}else if (c == backCommand1) {
			display.setCurrent(list3);}

	if (c == noOfof){
		 display.setCurrent(noOFof);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	else if (c == schedule) {
			display.setCurrent(form2);}

	   }
	   else if (d == noOFof){
	 if (c == backCommand1) {
			display.setCurrent(list4);}

	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}
	   }
	   else if (d == F1){
	if (c == show){
		 display.setCurrent(form);
	 //str = tb.getString();

		}else if (c == backCommand1) {
			display.setCurrent(list4);}
	 else if (c == exitCommand) {
			destroyApp(true);
			notifyDestroyed();}

	   }
	}

}

وهذا كود ال servlet

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class NS1 extends HttpServlet {

	@Override
	public void init() {
	}

	@Override
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,
IOException {

		DataInputStream in = new DataInputStream(
				(InputStream)request.getInputStream());

		String db = in.readUTF();


		String message ="jdbc:mysql://localhost:3306/mare_nav" + ",root," + "";
		try {

			connect(db.toLowerCase().trim());



		} catch (Throwable t) {

		}
		response.setContentType("text/plain");
		response.setContentLength(message.length());
		PrintWriter out = response.getWriter();
		out.println(message);
		in.close();
		out.close();
		out.flush();
	}

	@Override
	public void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException,
			IOException {

		doPost(request,response);
	}

	/* This Method connects to MySQL database*/

	private void connect(String db)

	throws Exception {
		String c="SELECT _id from rooms ";
if(db=="1")
{
   c= "SELECT buil_id from rooms ";
}

		// Establish a JDBC connection to the MySQL DataBase server.
		//Class.forName("org.gjt.mm.mysql.Driver");
		Class.forName("com.mysql.jdbc.Driver").newInstance();
		Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mare_nav", "root", "");
 Statement theStatement=conn.createStatement();

   ResultSet theResult=theStatement.executeQuery(c);


		   }
}

اتمنى منكم قراءة الكود وتوضيح اين مكان الخطاء

اكرر عذري الشديد

#12

شكراا جزيلا لكم جميعااا

لاني وصلت لحل بفضل من الله ثم منكم

كانت المشكلة في كود ال servlet

هذا هوا الكود الصحيح

import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class NS1 extends HttpServlet {
 private ServletConfig config;
  Connection theConnection;
  String c="";
	@Override
	public void init(ServletConfig config)  throws ServletException{
	 this.config=config;
   }

	@Override
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,
IOException {

		DataInputStream in = new DataInputStream(
				(InputStream)request.getInputStream());

		String db = in.readUTF();


		c="SELECT buil_id from rooms ";
		response.setContentType("text/plain");
		 PrintWriter out = response.getWriter();

		try {

			if(db.matches("2")){

				c="SELECT map_id from rooms ";
			}else if(db.matches("1")){
				 c="SELECT Room_id from rooms ";

				}


		   Class.forName("com.mysql.jdbc.Driver");


   //Connect to emaildb Data source
   theConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mare_nav", "root", "");


   Statement theStatement=theConnection.createStatement();

   ResultSet theResult=theStatement.executeQuery(c); //Select all records from emaillists table.

  //Fetch all the records and print in table
	while(theResult.next()){

  out.println( theResult.getString(1) );
  //out.println(theResult.getString(2) );





	}

  theResult.close();//Close the result set

  theStatement.close();//Close statement

  theConnection.close(); //Close database Connection
  in.close();
		 out.close();
		 out.flush();

  }catch(Exception e){

   out.println(e.getMessage());//Print trapped error.

  }






		 catch (Throwable t) {

		}

	}

	@Override
	public void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException,
			IOException {

		doPost(request,response);
	}

	/* This Method connects to MySQL database*/



	public void destroy(){

  }
}

اما اخذ الصورة من السيرفر فنحن مضطرين الى ذالك

لان من المفروض ان يكون البرنامج عام وليس خاص لمبنى معين

اكرر شكري وامتناني

#13

على الرحب و السعة ...

ياريت كل الاعضاء يتعبو شوي بالبحث عن حل المشكلة

و نحن نقدم كل المساعدة الممكنة عن سؤال عن شئ محدد

اما وضع كود كامل طوله 4 صفحات و طلب ايجاد الخطا!! فهذا غير منطقي

مع تمنياتي بالتوفيق.. و اهلا بكم في الفريق العربي للبرمجة

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#14

ان شاء الله هذا راح يكون اخر استفسار لنا

اذا اردنا استرداد نقاط من servlet وطبقنا ال ant algorithm على ال j2me

هل هذا يكون سهل على ال j2me او انوا راح يزود في حجم البرنامج

وهل فكرة انو يروح يجيب النقاط كل مره من ال servlet راح تقلل من سرعة الاستجابة

واذا كان هناك فكرة اخرى نرجوا الافادة بها

وشكرااا جزيلاااا

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…