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

كيفية الربط بين M V C

بدأه hamza11986 في 7 أبريل 2009 · 6 رد · 1,026 مشاهدة · في JavaEE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

تبعا لالموضوع السابق

أريد أن أستفسر عن كيفية الربط بين M V C بشكل دقيق ولو كان هناك مثال يكون أفضل

لأنني عملت تجربة بس البرنامج ما اشتغل وهي الموجودة في الموضوع السابق الذي اشرت له....

تحياتي

#2

لو انت شغال j2ee

حط كود الmain بتاع الكلاس testinsert

اللى هو مسئول عن حفظ الsession

فى action واربطه بالform bean

وفى صفحة الjsp

اعمل form action=your action

تحياتى

أُحبُّ الصَّالِحِينَ وَلسْتُ مِنْهُمْ ××× لَعَلِّي أنْ أنَالَ بهمْ شَفَاعَهْ

وَأكْرَهُ مَنْ تِجَارَتُهُ المَعَاصِي ××× وَلَوْ كُنَّا سَواءً في البضَاعهْ

#3

هانجعل السؤال بشكل أخر

ماالذي يجب ان يكون في web.xml

وstruts-config.xml

وعموما مالذي يجعل action تتصل بdata

أسئلة معلقة لحد الان

تحياتي ومحبتي

#4

واضح انك شغال struts

لو افترضنا انك عايز تسجل بيانات الصفحة فى الداتا بيز

الاكشن controller بتاعك هياخد البيانات دى من View اللى هى صفحة ال jsp من خلال الكلاس اللى فى ال Model وهيعمل الserver validation بال form bean

وهى عباره عن كلاس بها اسماء الcontrols بتاعتك على الصفحة

وهيسجل البيانات فى الdatabase من خلال ال

DataAccesslayer

وبالنسبه للconfiguration ال struts بيعمل اغلبها لوحده

يارب اكون ساعدتك

أُحبُّ الصَّالِحِينَ وَلسْتُ مِنْهُمْ ××× لَعَلِّي أنْ أنَالَ بهمْ شَفَاعَهْ

وَأكْرَهُ مَنْ تِجَارَتُهُ المَعَاصِي ××× وَلَوْ كُنَّا سَواءً في البضَاعهْ

#5

السلام عليكم

أرجو منكم مشاركتنا بالنقاش

أوكي أنا حاحط كود cstruts-config/web.xml

+controleur+data+vue

ثم نرى قولكم

هل به خطأ محدد أم أن الامر جيد

1- vue: وحاحط الفورم فقط

اقتباس
<html:form id="form1" name="Ident" method="get" action="Ident.do">

<table width="72%" height="213" border="0">

<tr>

<td width="46%" height="43" class="Style1"><div align="center" class="item_desc">

<div align="right" class="item_desc">Pseudo: </div>

</div></td>

<td width="54%" class="Style1"><div align="center">

<div align="left">

<input name="Pseudo" type="text" id="Pseudo" value="" size="20"/>

</div>

</div></td>

</tr>

<tr>

<td height="43" class="Style1"><div align="center" class="item_desc">

<div align="right" class="item_desc">Password : </div>

</div></td>

<td class="Style1"><input name="password" type="text" id="password" value="" size="20" />

<div align="left"></div></td>

</tr>

<tr>

<td height="43" class="Style1"><div align="center" class="item_desc">

<div align="right" class="item_desc">Type : </div>

</div></td>

<td class="Style1"><input name="type" type="text" id="type" value="" size="20" />

<div align="left"></div></td>

</tr>

<tr>

<td height="74" class="Style1"></td>

<td class="Style1"><input name="Submit2" type="submit" class="Style6" value="Envoyer" /></td>

</tr>

</table>

</html:form>

controleur

اقتباس
package com.struts.controleur;

import javax.servlet.http.*;

import org.apache.struts.action.*;

import org.hibernate.Session;

import com.location.Identification;

import com.struts.data.*;

import com.util.HibernateUtil;

public class AjoutIdentAction extends Action{

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest req,

HttpServletResponse res) throws Exception {

String resultat = null;

String Pseudo = ((IdentForm) form).getPseudo();

String password =((IdentForm) form).getPassword();

String type=((IdentForm) form).getType();

try{

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Identification I=new Identification();

I.setPassword(password);

I.setPseudo(Pseudo);

I.setType(type);

session.save(I);

session.getTransaction().commit();

HibernateUtil.getSessionFactory().close();

resultat = "succes";

}catch(Exception ex){

HibernateUtil.getSessionFactory().close();

resultat = "echec";

}

return mapping.findForward(resultat);

}

}

data

اقتباس
package com.struts.data;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.*;

import org.apache.struts.action.ActionForm;

public class IdentForm extends ActionForm{

String pseudo;

String password;

String type;

public String getPseudo() {

return pseudo;

}

public void setPseudo(String pseudo) {

this.pseudo = pseudo;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

ActionErrors errors = new ActionErrors();

return errors;

}

public void reset(ActionMapping mapping, HttpServletRequest request) {

this.password="";

this.pseudo="";

this.type="";

}

}

web.xml

اقتباس
<?xml version="1.0" encoding="UTF-8"?>

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"'>http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>

location</display-name>

<servlet>

<servlet-name>action</servlet-name>

<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

<init-param>

<param-name>config</param-name>

<param-value>/WEB-INF/struts-config.xml</param-value>

</init-param>

<load-on-startup>2</load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>action</servlet-name>

<url-pattern>*.do</url-pattern>

</servlet-mapping>

<welcome-file-list>

<welcome-file>index.html</welcome-file>

<welcome-file>index.htm</welcome-file>

<welcome-file>index.jsp</welcome-file>

<welcome-file>default.html</welcome-file>

<welcome-file>default.htm</welcome-file>

<welcome-file>default.jsp</welcome-file>

</welcome-file-list>

</web-app>

struts-config.xml

اقتباس
<?xml version="1.0" encoding="UTF-8"?>

<struts-config>

<form-beans type="org.apache.struts.action.ActionFormBean">

<form-bean name="Ident" type="com.struts.data.IdentForm" />

</form-beans>

<action-mappings type="org.apache.struts.action.ActionMapping">

<action path="/Ident" scope="request"

name="Ident" type="com.struts.controleur.AjoutIdentAction">

<forward name="succes" path="/index.html" redirect="false"/>

<forward name="echec" path="/contact.jsp" redirect="false"/>

</action>

</action-mappings>

</struts-config>

#6

لما أضغط إرسال

الصفحة تعود لنفسها مباشرة

والله لا أدري ما الخطا هناك

#7

there is no error in the code or configuration

you can change the form method to post

we might say that "GET" is basically for just getting (retrieving) data

whereas "POST" may involve anything, like storing or updating data,

or ordering a product, or sending E-mail.

try it

أُحبُّ الصَّالِحِينَ وَلسْتُ مِنْهُمْ ××× لَعَلِّي أنْ أنَالَ بهمْ شَفَاعَهْ

وَأكْرَهُ مَنْ تِجَارَتُهُ المَعَاصِي ××× وَلَوْ كُنَّا سَواءً في البضَاعهْ

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