Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

peer-topeer Networks phần 3 ppt
Nội dung xem thử
Mô tả chi tiết
P1: OTE/SPH P2: OTE
SVNY285-Loo October 18, 2006 8:41
Better Development Environment 45
It is useful and more convenient in the learning and testing process. I recommendyou to enable the invoker servlet if you are not familiar with Tomcat. You
can enable this function by modifying the web.xml under the conf path.
Steps to enable the invoker servlet are as follows:
1. Locate the following two blocks in the web.xml file in the conf directory.
<!
<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>
>
<!−
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
>
2. Remove the first line and last line of the above two blocks (i.e., <! and
>).
3. Save the web.xml file. You can turn off this function by adding back the first
and last line to the blocks.
4. Create classes path under the C:\Tomcat 5.5\webapps\ROOT\WEB-INF.
5. Copy the simple.class of this book to the following path:
C:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes
6. Start a web browser.
7. Type http://localhost:8080/servlet/simple as the URL. The browser will display
the screen as illustrated in Fig. 5.15.
Figure 5.15. Screen of the simple servlet
P1: OTE/SPH P2: OTE
SVNY285-Loo October 18, 2006 8:41
46 5. Web Server and Related Technologies
5.5.4 Deployment of Servlets
It will be better to put the source files and compiled files (i.e., the class files) in
different directories when you have a lot of programs in your application. If you
are using an IDE tool (such as Jbuilder), then the IDE will take care of compilation
and put the class file in the right directory. However, if you do not have an IDE on
your computer, you can use the following command:
javac –d directory of the class name.java
For example, the following command will compile a simple.java program
and store the simple.class file in the c:\Tomcat 5.5\webapps\ROOT\WEBINF\classes.
e.g.,javac –d c:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes simple.java
You can also use a wild card character ‘*’ to compile all programs in the current
directory.
e.g.,javac –d c:\Tomcat 5.5\webapps\ROOT\WEB-INF\classes *.java
It is not an interesting task to type these commands many times a day. It is also
an error-prone exercise unless you have very good typing skills. You can use a
batch file (or script file in unix or linux environment) to make your life easier. A
tom.bat file can be found in the website of this book. The contents of this file are
quite simple:
javac -d c:\Tomcat 5.5\webapps\root\web-inf\classes %1.java
Format of the command to invoke the batch file is tom servlet name
The following command will compile the simple.java program with the batch
file:
tom simple
Note that there is no need to type .java.
5.6 Directories
Tomcat has a lot of sub-directories, so it is quite complicated for beginners. You
need some basic understanding of the directories and the mapping mechanism of
Tomcat.