ApacheとTomcatの連携 |
[root src]# tar zxvf jakarta-tomcat-connectors-jk2-2.0.1-src.tar.gz [root src]# cd jakarta-tomcat-connectors-jk2-2.0.1-src/jk/native2/ [root native2]#./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-tomcat41=/usr/local/tomcat [root native2]# make |
/usr/bin/ld: cannot find -lapr collect2: ld returned 1 exit status make[1]: *** [../../../build/jk2/apache2/jkjni.la] Error 1 make[1]: Leaving directory `/usr/local/src/jakarta-tomcat-connectors-jk2-2.0.1-src/jk/native2/server/a pache2' make: *** [jk2-build] Error 1 |
[root native2]# cd /usr/local/apache2/lib [root lib]# ln -s libapr-0.so libapr.so |
[root native2]# cd ../build/jk2/apache2/ [root apache2]# cp -p mod_jk2.so /usr/local/apache2/modules/. |
# Example: # LoadModule foo_module modules/mod_foo.so LoadModule jk2_module modules/mod_jk2.so <--この1行を追加します。 |
[root apache2]# cp /usr/local/src/jakarta-tomcat-connectors-jk2-2.0.1-src/jk/conf/workers2.properties /usr/local/apache2/conf/. |
<!-- Define a non-SSL Coyote HTTP/1.1 Connector on port 8080 --> <!-- <-- この行を追加します。8080の項目をコメントにする事で無効にします。 <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8080" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="100" debug="0" connectionTimeout="20000" useURIValidationHack="false" disableUploadTimeout="true" /> --> <-- この行を追加します。 <!-- Define a Coyote/JK2 AJP 1.3 Connector on port 8009 --> <Connector className="org.apache.coyote.tomcat4.CoyoteConnector" port="8009" minProcessors="5" maxProcessors="75" enableLookups="true" redirectPort="8443" acceptCount="10" debug="0" connectionTimeout="0" useURIValidationHack="false" protocolHandlerClassName="org.apache.jk.server.JkCoyoteHandler"/> |
アプリケーションルート(/usr/local/apache2/htdocs/image-view) |--WEB-INFディレクトリ(/usr/local/apache2/htdocs/image-view/WEB-INF) |--classesディレクトリ(/usr/local/apache2/htdocs/image-view/WEB-INF/classes) |--サーブレットクラスファイル(/usr/local/apache2/htdocs/mage-view/WEB-INF/classes/HelloWorld.class) |--web.xmlファイル(/usr/local/apache2/htdocs/image-view/WEB-INF/web.xml) |
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class HelloWorld extends HttpServlet{ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/html"); PrintWriter out = res.getWriter(); out.println("<html>\n<head>\n<title>HelloWorld!</title>\n</head>\n<body>\n"); out.println("<p>Hello World.</p>\n"); out.println("</body>\n</html>\n"); out.close(); } } |
jjavac -classpath /usr/local/tomcat/common/lib/servlet.jar HelloWorld.java |
context=/examples debug=0 [uri:/examples1/*] info=A second webapp, this time going to the second tomcat only. group=lb_1 debug=0 [uri:/examples/servlet/*] info=Prefix mapping [uri:/examples/*.jsp] info=Extension mapping [uri:/examples/*] info=Map the whole webapp [uri:/examples/servlet/HelloW] info=Example with debug enabled. debug=10 [uri:/gallery/jpg/*] <-- ここで指定したURLパターンにマッチした場合にtomcatへ転送します。 |
<!-- Tomcat Root Context --> <!-- <Context path="" docBase="ROOT" debug="0"/> --> <!-- Append Start --> <-- ここから追加 <!-- Tomcat image Context --> <Context path="/gallery/jpg" docBase="/usr/local/apache2/htdocs/image-view" debug="0" reloadable="true"/> <!-- Append End --> <-- ここまで追加 <!-- Tomcat Examples Context --> <Context path="/examples" docBase="examples" debug="0" reloadable="true" crossContext="true"> |
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <-- ここでサーブレット名と、クラスの関連づけを行います。 <servlet-name>HelloWorld</servlet-name> <servlet-class>HelloWorld</servlet-class> </servlet> <servlet-mapping> <-- ここでサーブレット起動URLとの関連づけを行います。 <servlet-name>HelloWorld</servlet-name> <url-pattern>/HelloWorld</url-pattern> </servlet-mapping> </web-app> |
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <servlet-mapping> <servlet-name>invoker</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app> |
お問い合わせはwebmaster@ryouto.jpまで。
Copyright (C)2003 ryouto.jp. All Rights Reserved.