السلام عليكم ورحمة الله وبركاته
اخوتي الاعزاء بعد العناء تمكنت من عمل فكرة بسيطة الى chat ,
وعندما عرضت المشاركة في منتدى قسم j2ee وجهني اخي العزيز علاء الصالحي
الى ان اضع مشاركتي في هذا القسم المبارك لكي باذن الله ومعونتكم ان تجدوا لي حل الله يعزكم ويبارك فيكم وانا طالب دراسات عليا من العراق
فاتمنا ان تعينوني مثلما اعانني القائمين على قسم j2ee وكانوا خير موجه واستاذ الله يبارك فيهم :wub:
(((
لانهم إن شاء الله سوف ينتهي مشروعي من الناحية العملية بعد اكمال هذه الفكرة . وإن شاء الله ان كملت هذه الفكرة فانها سوف تعم الفائدة الى الجميع (إن شاء الله تعالى ). انتظر مشاركاتكم اخوتي الله يبارك فيكم
)))
حيث تعرض صفحة عند كل مشترك فيها
1- صفحة التي يكتب فيها .
2- صفحة يعرض فيها الذي كتبه والشخص الاخر الذي كتبه ايضا .
ملاجظة
البرنامج يعتمد على قواعد البيانات بصورة كاملة
البرنامج يعمل بصورة صحيحة الحمد لله ((( لكن ))) توجد حالة هو انه الشخص عندما يرسل له من شخص اخر لا يعرف ذلك الا ان يقوم بعملة refresh وهذا يسبب عملة اعادة كتابة بياناته التي ارسلها سابقا
كمثال توضيحي
احمد ارسل ( hi ) الى محمد
عندما محمد يدخل يجد كلمة (hi ) وعندما محمد يرسل (hellow ) الى احمد
فعلى احمد ان يقوم بعمل refresh ليجد ما كتبه محمد
ولكن المشكلة تكمن في انه عندما احمد يعمل refresh فانه سوف يتضاعف البيانات السابقة التي ارسالها اي عمليا يوضحه ما يلي
احمد
hi
محمد يجد hi
فيرد hellow
احمد لايستطيع ان يجد ما كتبه محمد الاعند عمل refresh فتحصل المشكلة حيث يجد
hi
hi
hellow
وهذه قاعدة البيانات
DROP TABLE IF EXISTS `mahmood`.`ch`; CREATE TABLE `mahmood`.`ch` ( `chat` varchar(100) collate utf8_unicode_ci NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
DROP TABLE IF EXISTS `mahmood`.`ch1`; CREATE TABLE `mahmood`.`ch1` ( `chat1` text collate utf8_unicode_ci NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
وهذه البرمجة بالتسلسل الشخص الاول
<%--
Document : fieldset
Created on : Mar 9, 2010, 7:04:16 PM
Author : Mahmood2010
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chat</title>
</head>
<body text="#00CC66">
<%-- this is text area to veiw text--%>
<FIELDSET>
<LEGEND>Reading Text Areas</LEGEND>
You typed:
<p>
<TEXTAREA NAME="textarea2" ROWS="10" cols="25">
<%@ page import="java.sql.*" %>
<%-- this is DB of the first user--%>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
st = conn.createStatement();
rs = st.executeQuery("select * from ch");
while(rs.next()) {
%>
<%= rs.getString("chat") %>
<%
}
%>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
Ooops, something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
<%-- this is DB of the second user--%>
<%
Connection conn1 = null;
Statement st1 = null;
ResultSet rs1 = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn1 = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
st1 = conn1.createStatement();
rs1 = st1.executeQuery("select * from ch1");
while(rs1.next()) {
%>
<%= rs1.getString("chat1") %>
<%
}
%>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
Ooops, something bad happened:
<%
} finally {
if (rs1 != null) rs.close();
if (st1 != null) st.close();
if (conn1 != null) conn.close();
}
%>
</TEXTAREA>
</p>
</FIELDSET>
<%-- this is text area to insert text by first user--%>
<FIELDSET>
<LEGEND>Submitting Text Areas</LEGEND>
Please enter your text:
<FORM METHOD="get" action="io.jsp">
<BR>
<TEXTAREA NAME="textarea1" ROWS="5" cols="25"></TEXTAREA>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</FIELDSET>
</body>
</html><%--
Document : io
Created on : Mar 9, 2010, 7:29:00 PM
Author : Mahmood2010
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("textarea1");
session.putValue("textarea1",user);
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into ch values ('"+user+"')");
%>
<jsp:forward page="fieldset.jsp"/>
</body>وهذه برمجة الشخص الثاني
<%--
Document : fieldset
Created on : Mar 9, 2010, 7:04:16 PM
Author : Mahmood2010
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chat</title>
</head>
<body text="#0000FF">
<%-- this is text area to veiw text--%>
<FIELDSET>
<LEGEND>Reading Text Areas</LEGEND>
You typed:
<p>
<TEXTAREA NAME="textarea2" ROWS="10" cols="25">
<%@ page import="java.sql.*" %>
<%-- this is DB of the first user--%>
<%
Connection conn = null;
Statement st = null;
ResultSet rs = null;
try
{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
st = conn.createStatement();
rs = st.executeQuery("select * from ch");
while(rs.next()) {
%>
<%= rs.getString("chat") %>
<%
}
%>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
Ooops, something bad happened:
<%
} finally {
if (rs != null) rs.close();
if (st != null) st.close();
if (conn != null) conn.close();
}
%>
<%-- this is DB of the second user--%>
<%
Connection conn1 = null;
Statement st1 = null;
ResultSet rs1 = null;
try {
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn1 = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
st1 = conn1.createStatement();
rs1 = st1.executeQuery("select * from ch1");
while(rs1.next()) {
%>
<%= rs1.getString("chat1") %>
<%
}
%>
<%
} catch (Exception ex) {
ex.printStackTrace();
%>
Ooops, something bad happened:
<%
} finally {
if (rs1 != null) rs.close();
if (st1 != null) st.close();
if (conn1 != null) conn.close();
}
%>
</TEXTAREA>
</p>
</FIELDSET>
<%-- this is text area to insert text by second user--%>
<FIELDSET>
<LEGEND>Submitting Text Areas</LEGEND>
Please enter your text:
<FORM METHOD="get" action="io2.jsp">
<BR>
<TEXTAREA NAME="textarea3" ROWS="5" cols="25"></TEXTAREA>
<BR>
<INPUT TYPE="SUBMIT" VALUE="Submit">
</FORM>
</FIELDSET>
</body><%--
Document : io
Created on : Mar 9, 2010, 7:29:00 PM
Author : Mahmood2010
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%@ page import ="java.sql.*" %>
<%@ page import ="javax.sql.*" %>
<%
String user=request.getParameter("textarea3");
session.putValue("textarea3",user);
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection con = DriverManager.getConnection("jdbc:mysql://localhost/mahmood","root","password");
Statement st= con.createStatement();
ResultSet rs;
int i=st.executeUpdate("insert into ch1 values ('"+user+"')");
%>
<jsp:forward page="fieldset1.jsp"/>
</body>
</html>فارجو من اخوتي الكرام ان يقراؤ فكرتي بتمهل وان يدعموني
فارجو منهم ان يعينوني بما فتح الله عليهم من علم وان يضعون مشاركاتهم القبمة التي تعودنا عليها
سلامي
اخوكم
محمود سامي