Web Application Structure هيكل تطبيقات الواب

Sang Shin , sang.shin@sun.com , www.javapassion.com/j2ee سانغ شين ، sang.shin @ sun.com ، www.javapassion.com/j2ee




This hands-on lab takes you build a simplest possible Web application using NetBeans.  You are going to add a servlet and JSP page to the application.  You will also learn the structure of a Web application. التدريب العملي في هذا المختبر يمكنك من بناء تطبيق الويب بابسط طريقة ممكنة باستخدام Netbeans. ستقوم بإضافة Servlet و صفحه JSP الى التطبيق. يمكنك ايضا معرفة هيكل تطبيقات الواب.

Expected duration: 60 minutes (excluding homework) المده المتوقع : 60 دقيقة (باستثناء العمل المنزلي)


Software Needed البرامج اللازمة

Before you begin, you need to install the following software on your computer.  The downloading and installation instruction of JDK and NetBeans can be found in Exercise 0 below . قبل البدء ، لا بد من تثبيت البرامج التالية على جهاز الكمبيوتر الخاص بك. تجد كيفية تنزيل وتثبيت JDK و Netbeans في تمرين 0 ادناه.


OS platforms you can use اذا اردت يمكنك استخدام المنصات التالية


Change Log غير المفتاح


Lab Exercises معمل تدريبات



Exercise 0: Downloading and installation of JDK and NetBeans تمرين 0 : تثبيت Java وبيئة التطوير المتكاملة Netbeans.


You can install JDK and NetBeans using various types of bundles - they all should work.  Here, you are going to install JDK first and then NetBeans IDE. يمكنك تثبيت JDK و Netbeans باستخدام أنواع مختلفة من الحزم -- انها من المفترض أن تعمل جميعا. هنا، سنقوم بتثبيت JDK اولا وبعد ذلك Netbeans بيئة التطوير المتكاملة.

(0.1) Install JDK 6 (0.1) تثبيت JDK 6


If you already have installed JDK 5 or 6 on your machine, you can skip this step.  (Or if you choose to do so, you can install JDK along with NetBeans by choosing "Web and Java EE" NetBeans bundle in step 0.2 below.) اذا كنت قد قمت بتثبيت JDK 5 او 6 على جهازك، يمكنك تخطي هذه الخطوة.( أو إذا أردت أن تفعل ذلك ، يمكنك تثبيت JDK مع Netbeans في نفس الوقت عن طريق اختيار حزمة "Web and Java EE" netbeans في الخطوة 0.2 ادناه)

1. Download JDK Update x (as of June 28th, 2008, the Update 6 is the latest) from the download page. تحميل JDK التحديث العاشر (فى يونيو 28th ، 2008 ، الإصدار 6 هو آخر الإصدارات) من صفحة التنزيل.



2. Select the Platform and check the "I agree to the Java SE Development Kit 6 Licence Agreement". إختر المنصة ثم ضع علامة أمام "I agree to the Java SE Development Kit 6 Licence Agreement".



3. Download the JDK 6 package either directly or using Sun Download Manager.  (Use Sun Download Manager if your network is not reliable.) حمل حزمة JDK 6 إما بصورة مباشرة او باستخدام Sun Download Manager.( استخدم Sun Download Manager اذا كان إتصال الإنترنت عندك غير مستقر.)



4. Save the file in the local file system. إحفظ الملف في نظام الملفات المحلية.



5. Install JDK. قم بتثبيت JDK.

(0.2) Install NetBeans (0.2) تثبيت Netbeans


1. Download NetBeans IDE 6.1 from the download page. حمل Netbeans IDE 6.1 من صفحه التحميل .



2. Choose Platform and select NetBeans IDE bundle as following. اختر المنصة ثم اختر حزمة بيئة التطوير المتكاملة Netbeans على النحو التالي.



Exercise 1: Create a new Web Application تمرين 1 : إنشاء تطبيق واب جديد

In this exercise, you are going to create a simplest possible Web application that contains a single index.jsp initially.  You will then add a new Servlet and a new JSP file to the application. وفي هذا التمرين، ستقوم بإنشاء تطبيق واب بابسط طريقة ممكنة و الذي سيحتوي في البداية على صفحة واحدة index.jsp. و من ثمة يمكنك إضافة Servlet وملف JSP.

  1. Create a new NetBeans project انشاء مشروع جديد netbeans
  2. Build and run the project بناء و تنفيذ المشروع
  3. Modify the index.jsp of the application تعديل index.jsp
  4. Add a Servlet to the application اضافة Servlet
  5. Add a new JSP to the application إضافة JSP

    (1.1) Create a new NetBeans project (1.1) انشاء مشروع جديد netbeans

    0. Start NetBeans IDE if you have not done so yet. شغل netbeans بيئة تطوير متكاملة اذا كنت لم تفعل ذلك حتى الان.
    1. Select File -> New Project (Ctrl+Shift+N) .   (Figure-1.10 below) The New Project dialog box appears. اختر ملف --> مشروع جديد (Ctrl+Shift+N). (الشكل أدناه - 1.10 ) تظهر نافذة المشروع الجديد .


    Figure-1.10: Create a new NetBeans projectالرسم - 1.10 : انشاء مشروع جديد netbeans

    2. Under Choose Project pane, select Web under Categories and Web Application under Projects . في لوحة Choose Project ، اختر Web في اطار Categories وفي اطار Projects اختر Web Application. Click Next . انقر فوق التالي. (Figure-1.11 below) (الشكل ادناه - 1.11)


    Figure-1.11: Create a new Web application projectالرسم - 1.11 : انشاء تطبيق واب جديد

    3. Under Name and Location pane, for the Project Name field, type in MyFirstWebApp as project name. تحت لوحة Name and Location, في حقل إسم المشروع أدخل myfirstwebapp كإسم للمشروع. Click Next . انقر فوق التالي. (Figure-1.12 below) (الشكل ادناه - 1.12)


    Figure-1.12: Create MyFirstWebApp projectالرسم - 1.12 : انشاء مشروع myfirstwebapp

    4. Click Finish. انقر فوق إنهاء.


    5.  Observe that MyFirstWebApp project node appears with the IDE generated index.jsp file displayed in the source editor. 5. لاحظ ظهور وصلة مشروع Myfirstwebapp و تولد أوتوماتيكي لملف index.jsp في محرر النصوص. (Figure-1.13 below) (الشكل ادناه - 1.13)


    Figure-1.13: MyFirstWebApp project is createdالرسم - 1.13 : تم القيام بمشروع myfirstwebapp

    (1.2) Build and run the project (1.2) بناء وتنفيذ المشروع

    At this point, you have a useless but fully complete Web application which contains a single JSP file, index.jsp .  You are going to build and run the application. وعند هذه النقطه ، لديكم تطبيق واب كامل ولكنه عديم الفاءده يتضمن ملف JSP واحد ، index.jsp. سنقوم ببناء وتشغيل التطبيق.

    1. Right click MyFirstWebApp project node and select Run .  (Figure-1.20 below) انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر تنفيذ (الشكل ادناه - 1.20)


    Figure-1.20: Runالرسم - 1.20 : تشغيل

    2. The IDE then compiles any Java source files, and then deploys over the deployment platform - GlassFish V2 in this example.  It also displays the browser. تقوم بيئة التطوير المتكاملة IDE بتجميع جميع ملفات مصادر الجافا ، ثم تقوم بنشرها على منصة النشر deployment platform, في هذا المثال -- glassfish V2 ، كما انه يعرض المتصفح.


    Figure-1.21: Result of running the projectالرسم - 1.21 : نتيجة لتشغيل المشروع

    3. Observe that a browser is displayed accessing the application. لاحظ ظهور المتصفح من خلال التطبيق. (Figure-1.22 below) (الشكل ادناه - 1.22)


    Figure-1.22: Accessing the application from a browserالرسم - 1.22 : النفوذ إلى التطبيق من خلال المتصفح


    (1.3) Modify the index.jsp of the application (1.3) تعديل index.jsp الخاص بالتطبيق


    In this step, you are going to modify the index.jsp of the application. في هذه الخطوة ، ستقوم بتعديل index.jsp الخاص بالتطبيق.

    1. Double click index.jsp file under MyFirstWebApp ->Web Pages as shown in Code-1.30 below.  The code fragments that need to be modified are highlighted in bold and red-colored font. انقر نقرأ مزدوجا فوق ملف index.jsp تحت myfirstwebapp --> Web Pages على النحو المبين في المصدر - 1.30 ادناه. اجزاء المصدر التي تحتاج الى تعديل مكتوبة باللون الاحمر.

    <%@page contentType="text/html"%>
    <%@page 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>This is my first Web application</title>
        </head>
        <body>
        <h1>This is my first Web application</h1>
       
       
       
       
        </body>
    </html>

    Code-1.30: Modified index.jsp مصدر - 1.30 : تعديل index.jsp

    2. Right click MyFirstWebApp project node and select Run .  (Figure-1.31 below) انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر تنفيذ ( الشكل ادناه - 1.31)


    Figure-1.31: Run the projectالرسم - 1.31 : تنفيذ المشروع

    3. Observe that a browser is displayed with your change. لاحظ ظهور التغيير الذي أدخلته على المتصفح. (Figure-1.32 below) (الشكل ادناه - 1.32)


    Figure-1.32: Result of the running the applicationالرسم - 1.32 : نتيجة تنفيذ التطبيق

    (1.4) Add a Servlet to the application (1.4) اضافة Servlet الى التطبيق


    1. Right click MyFirstWebApp project node and select New->Servlet .  (Figure-1.40 below) The New Servlet dialog box appears. انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر New -> Servlet. الجديدة Servlet ظهور مربع New Servlet.


    Figure-1.40: Create a new servletالرسم - 1.40 : إنشاء Servlet جديدة

    2. For Class Name field, type in MyOwnServlet . أدخل MyOwnServlet في حقل Class Name
    3. For Package field, type in myownpackage . أدخل myownpackage في حقل Package. Click Next . انقر فوق التالي. (Figire-1.41 below) ( الشكل ادناه - 1.41)


    Figure-1.41: Create a new servletالرسم - 141 : إنشاء Servlet جديدة

    3. Click Finish of the Configure Servlet Deployment pane. انقر فوق انهاء في لوحة Configure Servlet Deployment (Figure-1.42 below) (الشكل ادناه - 1.42)


    Figure-1.42: Configure Servlet Deployment paneالشكل - 1.42 : لوحة Configure Servlet Deployment

    4. Observe now that you have one JSP file, index.jsp , and one servlet, MyOwnServlet.java in this application. لاحظ ان لديك ملف index.jsp JSP و ، myownservlet.java Servlet في هذا التطبيق. (Figure-1.43 below) (الشكل ادناه - 1.43)


    Figure-1.43: index.jsp and MyOwnServlet.javaالرسم - 1.43 : index.jsp وmyownservlet.java

    5. Right click MyFirstWebApp project node and select Run . انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر تنفيذ.
    6. Observe that the browser is refreshed. نلاحظ ان لمتصفح منتعشه.




    (1.5) Add a new JSP called MyOwnJSP.jsp to the application (1.5) أضف JSP جديدة الى التطبيق و سمها myownjsp.jsp

    1. Right click MyFirstWebApp project node and select New->JSP . انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر New -> JSP. (Figure 1.50 below)


    Figure 1.50: Create a new JSP fileالرسم - 1.50 : إنشاء ملف JSP جديد

    2.  For the JSP File Name field, type in MyOwnJSP . 2. أدخل MyOwnJSP في حقل JSP File Name (Figure 1.51 below)


    Figure 1.51: Name and Location pane الرسم - 1.51 : لوحة Name and Location

    3. Observe that MyOwnJSP is added to the project. نلاحظ ان أضيف Myownjsp الى المشروع.



    4. Right click MyFirstWebApp project node and select Run . انقر بزر الفأرة الايمن على عقده المشروع myfirstwebapp واختر تنفيذ.
    5. Observe that the browser is refreshed.   In the subsequent exercise, you are going to modify and access MyOwnJSP.jsp . لاحظ انتعاش المتصفح. في التمرين التالي ستقوم بتعديل myownjsp.jsp.



    Summary خلاصة

    In this exercise,  you have built and run a simplest possible Web application that contains a single index.jsp page first and then add a new JSP page and a new servlet. وفي هذه التمرين، قمت ببناء وتنفيذ تطبيق واب بأسهل طريقة ممكنة و يحتوي التطبيق على index.jsp في أول الأمر وبعد ذلك قمنا بإضافة صفحة JSP و Servlet .

    return to the top عودة الى الاعلى



    Exercise 2: Look under the hood of the MyFirstWebApp application تمرين 2 : نظرة داخلية داخل لمصدر myfirstwebapp

    In this exercise, you are going to examine the things under the hood such as web.xml . وفي هذه العملية ، سنقوم بدراسة ما يجري في الكواليس* مثال web.xml.


    (2.1) Examine the Web application project structure in Files view (2.1) دراسة لبنية مشروع تطبيق الواب التي تظهر في شاشة عرض الملفات

    A Web application is made of JSP files, Servlets, and library files.  The MyFirstWebApp application has two JSP files, index.jsp and MyOwnJSP.jsp , a single servlet, MyOwnServlet.java , and default library files.  You can add new JSP files, new Servlets, and new library files to the application as you did in Exercise 1. يتكون تطبيق الواب من ملفات JSP و Servlets و ملفات المكتبات. لتطبيق Myfirstwebapp ملفان JSP هما index.jsp و myownjsp.jsp و Servlet واحدة و myownservlet.java ، و ملفات المكتبه المبدئية. يمكنك اضافة كل من ملفات JSP و Servlets و ملفات المكتبه للتطبيق كما فعلنا في التمرين 1.

    Under NetBeans, you work with your project mostly under Projects view but you can also see it from Files view.  In this step, you are going to see the Files view of the MyFirstWebApp application.  A Files view of a project displays directories and files of the project in your local file system. في اطار Netbeans، تتعامل مع مشروعك غالبا تحت شاشة العرض Projects في اطار الرأي ، ولكنك تستطيع ايضا ان تتعامل معه تحت شاشة العرض Files. فى هذه الخطوة، سنقوم باكتشاف شاشة العرض Files لتطبيق Myfirstwebapp. شاشة العرض Files تعرض ملفات و مجلدات المشروع الوجودة في نظام الملفات الخاص بجهازك.

    1. Select Files tab window.  You should see the Files view of the MyFirstWebApp project. اختر جدول Files حتى تتمكن من رؤية ملفات مشروع Myfirstwebapp
    2. Expand src and expand java .  You should see all the Java files. إفتح مجلد src ثم افتح مجلد Java حتى تتمكن من رؤية جميع ملفات الجافا.
    3. Expand web .  You should see all JSP files (and HTML files if you have them).  (Figure 2.10 below) إفتح مجلد web. حتى تتمكن من رؤية جميع ملفات JSP (و رؤية ملفات HTML اذا كان لديك منهم). (2.10 الشكل ادناه)


    Figure-2.10: Files viewالرسم - 2.10 : شاشة عرض Files


    (2.2) Examine the WAR file structure (2.2) دراسة بنية ملف WAR


    A WAR is a zip file that contains all the pieces that are necessary for deploying the application over a deployment platform such as Tomcat or GlassFish.  In this step, you are going to see internal structure of the WAR file.  The internal structure of the WAR file is constructed from the contents of the web directory under build directory.  From NetBeans 6.1, if you "Run" the project, the WAR file is not created as a default.  You will have to "Build" project in order to see the WAR file under dist directory. WAR هو ملف مضغوط يحتوي على جميع الأجزاء الضروريه لنشر التطبيق من خلال منصة النشر deployment platform مثل Tomcat أو GlassFish. فى هذه الخطوة، سنقوم بدراسة البنية الداخلية لملف WAR. يتكون ملف WAR من دليل web تحت اطار الدليل build. منذ إصدار Netbeans6.1، اذا قمت بتنفيذ المشروع "run" ، فان ملف WAR لا يتكون بدءا. ستضطر إلى بناء المشروع "build" حتى تتمكن من رؤية ملف WAR تحت الدليل dist.

    0. Right click the MyFirstWebApp project node and select Build .  This is to create WAR file for the sake of this exercise. انقر بزر الفأرة الايمن على عقدة مشروع Myfirstwebapp ثم اختر Build لتتمكن من بناء ملف WAR لإتمام التمرين.



    1. Under Files view of the project, expand dist . تحت شاشة العرض Files للمشروع، إفتح مجلدdist You should see MyFirstWebApp.war file. يجب ان تتمكن من رؤية ملف Myfirstwebapp.war
    2. Expand MyFirstWebApp.war . إفتح Myfirstwebapp.war. You should see WEB-INF directory, MyOwnJSP.jsp and index.jsp in the root directory. يجب ان تتمكن من رؤية مجلد WEB-INF, لاحظ وجود Myownjsp.jsp و Index.jsp في الدليل الرئيسي.
    3. Expand WEB-INF->classes .  You should see myownpackage directory which then contains MyOwnServlet.class . - إفتح WEB-INF -> classes. يجب ان تتمكن من رؤية الدليل myownpackage الذي يحتوي على Myownservlet.class. (Figure 2.20 below) (الشكل ادناه - 2.20)


    Figure-2.20: MyFirstWebApp.warالرسم - 2.20 : Myfirstwebapp.war


    (2.3) Examine the web.xml (2.3) دراسة web.xml


    1. Click Projects tab window. انقر فوق نافذة علامة التبويب Projects
    2. Double click web.xml under WEB-INF directory.  Click XML to see the file in the XML file format. انقر نقرا مزدوجا على web.xml تحت دليل WEB-INF. انقر XML لتشاهد الملف في صيغة XML


    Figure-2.30: web.xmlالرسم - 2.30 : web.xml

    (2.4) Modify web.xml to use MyOwnJSP.jsp as a default JSP file to get displayed (2.4) تعديل web.xml لجعل myownjsp.jsp الصفحه الرئيسية


    1. Modify MyOwnJSP.jsp file as shown below.  The code fragments that need to be modified are highlighted in bold and red-colored font. Myownjsp.jsp تعديل الملف كما هو مبين أدناه. الأجزاء التي تحتاج الى تعديل تبرز واضحة باللون الأحمر.

    <%@page contentType="text/html"%>
    <%@page 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>My Own JSP Page</title>
        </head>
        <body>
        <h1>My Own JSP Page</h1>
       
       
       
       
        </body>
    </html>

    Code-2.40: Modified MyOwnJSP.jsp مصدر - 2.40 : تعديل Myownjsp.jsp

    2. Modify the web.xml as shown below.  The code fragments that need to be modified are highlighted in bold and red-colored font. تعديل web.xml كما هو مبين أدناه. الأجزاء التي تحتاج الى تعديل تبرز واضحة باللون الأحمر.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>MyOwnServlet</servlet-name>
            <servlet-class>myownpackage.MyOwnServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>MyOwnServlet</servlet-name>
            <url-pattern>/MyOwnServlet</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>MyOwnJSP.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    Figure-2.41: Modified web.xmlالرسم - 2.41 : تعديل web.xml

    3. Right click MyFirstWebApp project node and select Run .  You should see MyOwnJSP.jsp file gets displayed. انقر بزر الفأرة الايمن على عقده المشروع Myfirstwebapp واختر تنفيذ. يجب ان تشاهد عرض محتوى ملف Myownjsp.jsp.


    Figure-2.42: MyOwnJSP.jsp is displayed الشكل - 2.42 : عرض Myownjsp.jsp

    (2.5) Access MyOwnServlet (2.5) نفوذ Myownservlet


    1. Modify the MyOwnServlet.java file as shown below.   The code fragments that need to be modified are highlighted in bold and red-colored font. تعديل ملف myownservlet.java كما هو مبين أدناه. الأجزاء التي تحتاج الى تعديل تبرز واضحة باللون الأحمر.

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */

    package myownpackage;

    import java.io.*;
    import java.net.*;

    import javax.servlet.*;
    import javax.servlet.http.*;

    /**
     *
     * @author sang
     */
    public class MyOwnServlet extends HttpServlet {
      
        /**
        * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
        * @param request servlet request
        * @param response servlet response
        */
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            response.setContentType("text/html;charset=UTF-8");
            PrintWriter out = response.getWriter();
            try {
                // TODO output your page here
                out.println("<html>");
                out.println("<head>");
                out.println("<title>Servlet MyOwnServlet</title>"); 
                out.println("</head>");
                out.println("<body>");
                out.println("<h1>Servlet MyOwnServlet at " + request.getContextPath () + "</h1>");
                out.println("</body>");
                out.println("</html>");
                //
            } finally {
                out.close();
            }
        }

        // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
        /**
        * Handles the HTTP <code>GET</code> method.
        * @param request servlet request
        * @param response servlet response
        */
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
        * Handles the HTTP <code>POST</code> method.
        * @param request servlet request
        * @param response servlet response
        */
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        }

        /**
        * Returns a short description of the servlet.
        */
        public String getServletInfo() {
            return "Short description";
        }
        // </editor-fold>
    }
    Code-2.50: Modified MyOwnServlet.java مصدر - 2.50 : تعديل Myownservlet.java

    2. Right click MyFirstWebApp project node and select Properties . انقر بزر الفأرة الايمن على عقده المشروع Myfirstwebapp وتحديد Properties


    Figure-2.51: Propertiesالرسم - 2.51 : Properties

    3. Select Run . اختر تنفيذ.
    4. For the Relative URL: field, type in /MyOwnServlet .  This information is used by the NetBeans for accessing the Web application and is not part of the WAR file. بالنسبة لحقل Relative URL : أدخل /Myownservlet. وتستخدم هذه المعلومات من قبل Netbeans للوصول الى تطبيق الواب و هو ليس جزءا من ملف WAR


    Figure 2.52: Set Relative URLالرسم - 2.52 : تحديد Relative URL

    5.  Right click MyFirstWebApp project node and select Run .  You should see MyOwnServlet servlet is accessed as shown in Figure-2.53 below. 5. انقر بزر الفأرة الايمن على عقده المشروع Myfirstwebapp ثم اختر تنفيذ. يجب ان تتمكن من رؤية نفوذ Myownservlet Servlet كما هو مبين في الشكل ادناه - 2.53.


    Figure-2.53: MyOwnServlet accessedالرسم - 2.53 : نفوذ Myownservlet

    6. Modify the web.xml as shown below.  The code fragments that need to be modified are highlighted in bold and red-colored font. تعديل web.xml كما هو مبين أدناه. الأجزاء التي تحتاج الى تعديل تبرز واضحة باللون الأحمر.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>MyOwnServlet</servlet-name>
            <servlet-class>myownpackage.MyOwnServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>MyOwnServlet</servlet-name>
            <url-pattern>/MyOwnServletUseDifferentURL</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>MyOwnJSP.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    Figure-2.54: Modified web.xmlالرسم - 2.54 : تعديل web.xml

    7. Right click MyFirstWebApp project node and select Run .  You should experience an error. انقر بزر الفأرة الايمن على عقده المشروع Myfirstwebapp واختر تنفيذ. يجب عليك ان تجرب وجود هذا الخطأ.


    Figure 2.55: Error condition expectedالشكل - 2.55 : من المتوقع ان هناك خطأ في الشرط

    8. From your browser, go to directly to http://localhost:8080/MyFirstWebApp/MyOwnServletUseDifferentURL . من المتصفح الخاص بك ، انتقل مباشرة الى http://localhost:8080/myfirstwebapp/myownservletusedifferenturl.



    (2.6) Example deployment platform (2.6) مثال منصة النشر


    1.  Click Services tab window. 1. انقر فوق نافذة علامة التبويب Services
    2.  Expand Servers->GlassFish V2 and expand Web Applications .  You should see /MyFirstWebApp is deployed. 2. إفتح نطاق Servers -> glassfish V2 ثم إفتح Web Applications. يجب ان تتمكن من رؤية انتشار / MyFirstWebapp .


    Figure-2.60: Services platform الشكل - 2.60 : منصة Services

    2. Click back Projects tab window. عد و انقر فوق نافذة علامة التبويب Projects .


    Summary خلاصة

    In this exercise, you have looked into the project from the files view.  You looked into web.xml file of the application. وفي هذه التمرين، لقد نظرنا في ملفات المشروع من خلال نوافذ العرض. كما نظرنا في ملف Web.xml.

    Return to the top عودة الى الأعلى




    Homework Exercise (for people who are taking Sang Shin's "Java EE Programming online course") تمرين الواجب المنزلي (خاص بالمنخرطين بالدورة)


    1. 1. The homework is to modify the MyFirstWebApp project as described below.  (You might want to create a new project by copying the MyFirstWebApp project.)  You can name the homework project in any way you want but here I am going to call it MyFirstWebAppMyOwn . الواجب المنزلي يتمثل في تعديل مشروع MyFirstWebApp على النحو المبين اسفله. (قد تريد انشاء مشروع جديد عن طريق نسخ مشروع MyFirstWebApp ). يمكنك تسمية مشروع العمل المنزلي بأي إسم تريده ولكن هنا انا سأقوم بتسميته MyFirstWebAppMyOwn
    2 . 2. Send the following files to j2eehomeworks@sun.com with Subject as J2EEHomework-webappstructure. ارسل الملفات التالية الى j2eehomeworks@sun.com تحت عنوان J2EEHomework - webappstructure.

    return to the top عودة الى الاعلى