Thứ Bảy, 17 tháng 11, 2007

I. Cài đặt và cấu hình Tomcat server

I. Cài đặt và cấu hình Tomcat server:


1. Down load Tomcat:


- Điạ chỉ download: http://tomcat.apache.org/

- Copy và cài tomcat vào máy (Giả sử tôi cài vào thư mục: C:\Tomcat 5.5).


2. Tìm JDK:


- Click chuột phải vào Mycomputer.

- Chọn Properties.

- Chọn Advanced\ Enviroment Variable

- Trong cửa sổ thiết lập biến môi trường:



  • System variable:


    • chọn New và them vào: JAVA_HOME = C:\ Program Files\ Java\ jdk1.5


  • User Variable … ta thêm vào: PATH = ;%JAVA_HOME%\bin


3. Servlet compiler:


- Copy file servlet-api.jar trong thư mục C:\tomcat\common\lib\servlet-api.jar vào thư mục: C:\Program Files\java\jdk1.5\jre\lib\ext


4. File context.xml:


- Mở file: C:\tomcat\conf\context.xml

- thêm vào dòng text:

<!—the contents of this file will be loaded for each web application -->

< Context reloadable = “true”>

<!—default set of maitored resourse -->

<watched Resource>WEB-INF/web.xml</watcher Resource>

…….

</Context>


5. Enable the invoker servlet:


- Mở file: C:\tomcat\conf\web.xml

- Bỏ qua các chú thích được đánh dấu để chạy:

<!-- The "invoker" servlet, which executes anonymous servlet classes      -->

  <!-- that have not been defined in a web.xml file.  Traditionally, this   -->

  <!-- servlet is mapped to the URL pattern "/servlet/*", but you can map   -->

  <!-- it to other patterns as well.  The extra path info portion of such a -->

  <!-- request must be the fully qualified class name of a Java class that  -->

  <!-- implements Servlet (or extends HttpServlet), or the servlet name     -->

  <!-- of an existing servlet definition.     This servlet supports the     -->

  <!-- following initialization parameters (default values are in square    -->

  <!-- brackets):                                                           -->

  <!--                                                                      -->

  <!--   debug               Debugging detail level for messages logged     -->

  <!--                       by this servlet.  [0]                          -->

<!--

    <servlet>

        <servlet-name>invoker</servlet-name>

        <servlet-class>

          org.apache.catalina.servlets.InvokerServlet

        </servlet-class>

        <init-param>

            <param-name>debug</param-name>

            <param-value>0</param-value>

        </init-param>

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

    </servlet>

-->

……..

    <!-- The mapping for the invoker servlet -->

<!--

    <servlet-mapping>

        <servlet-name>invoker</servlet-name>

        <url-pattern>/servlet/*</url-pattern>

    </servlet-mapping>

-->


6. Kiểm tra lại:


- Bật server tomcat

- gõ vào IE: http://localhost:8080/

- Trong trang mặc định sẽ hiện:

If you're seeing this page via a web browser, it means you've setup Tomcat successfully. Congratulations!

- Chạy thử servlet: http://localhost:8080/Serlet-examples/


7. Plugin Eclipse:


- Download file tomcatPlugin….

- Giải nén vào thư mục plugin của eclipse

- Bật eclipse, vào Window\reference\

- Trong cửa sổ Reference:



  • Chọn Tomcat à vào cửa sổ cấu hình cho tomcat:


    • Tomcat version: tìm bản tương ứng mà ta đã cài.

    • Tomcat home: chọn tới thư mục cài tomcat (C:\Tomcat5.5)


  • Chọn Tomcat\Tomcat Manager App nhập vào:


    • Manager App url: http://localhost:8080/ manager

    • Manager App username: admin

    • Manager App password: admin

    • Clik OK



8. Tạo một servlet trong eclipse:


- Trong eclipse: chọn File\ New\Project…

- Chọn Java\ Tomcat Project

- Click Next

- bỏ chọn Use default

- Chọn thư mục : C:\Tomcat 5.5\webapps\servlets-examples

- project Name: servlets-examples

- Finish

Không có nhận xét nào: