大家都了解在ms家族中iis作為internet服務器可謂是赫赫有名,簡單,方便。
而且相關的web程序(asp,asp.net)也是比比皆是。
我們希望java開發的web程序可以和iis共存(共同使用80端口發布)。
這方面的教程網上很多,多數是copy之后又copy,以至于有些細節一直含糊不清,也導致我走了許多彎路。在此留個腳印防止日后的錯誤。
軟件及環境
windows server 2003
iis 6.0
tomcat 6.0.20
jdk 6.0
jk isapi_redirect-1.2.14 (很多情況下是由于isapi_redirect 的版本不符,我之前用過最新的1.2.28但是沒有整合成功 大家可以嘗試一下,這個軟件好像不太好找,服務器之家為大家提供了,速度更快)
1.安裝iis
控制面板--> 添加刪除程序 --> 添加刪除windows組件
測試
2.安裝java環境,這里要用jdk而不是jre
我安裝到
c:\java\jdk1.6
不要忘記配置環境變量
3.安裝tomcat
我的安裝目錄是
c:\tomcat6
啟動tomcat
測試8080端口
4.基本工作完成 下面我們進行整合
安裝isapi_redirect-1.2.14 當然也可以直接使用isapi_redirect-1.2.14.dll + 配置文件手動編寫,不過對于首次安裝還是建議使用安裝文件,防止配置文件書寫產生誤差導致整合不成功。
一路next
安裝目錄是
c:\program files\apache software foundation\jakarta isapi redirector
5.打開iis的管理界面
查看默認站點是否存在
中的jakarta的虛擬目錄
并查看屬性中
是否存在jakarta的篩選器。至于向上的綠色箭頭可能沒有(網上很多都指出要求由此,實際上只有配置之后首次訪問的時候,才進行加載)只要不是紅色就可以。
如果沒有則創建,
添加篩選器 名稱jakarta 文件地址 c:\program files\apache software foundation\jakarta isapi redirector\bin\isapi_redirect.dll
創建虛擬目錄
別名 jakarta (必須) 路徑 c:\program files\apache software foundation\jakarta isapi redirector\bin\
訪問權限
不要忘記 運行腳本 執行 勾選
ok
8.我們在tomcat app下面隨便建立個工程 我這里是目錄名0431la
修改配置文件
c:\program files\apache software foundation\jakarta isapi redirector\conf\uriworkermap.properties
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# uriworkermap.properties - iis # # this file provides sample mappings for example wlb # worker defined in workermap.properties.minimal # the general syntax for this file is: # [url]=[worker name] /admin/*=wlb /manager/*=wlb /jsp-examples/*=wlb /servlets-examples/*=wlb # optionally filter out all .jpeg files inside that context # for no mapping the url has to start with exclamation (!) !/servlets-examples/*.jpeg=wlb # # mount jkstatus to /jkmanager # for production servers you will need to # secure the access to the /jkmanager url # /jkmanager=jkstatus /0431la/*=wlb |
我們重啟tomcat 和 iis 并訪問測試
iis的重啟可以通過鼠標右鍵我的電腦 --> 管理 進行重啟
接下來我們可以進行測試
ok了 雖然這不是我們的最終結果 但是至少我們之前配置的沒有問題了
下面我們進行虛擬主機的配置
9.我們把0431la目錄放到c盤根目錄并配置tomcat的虛擬主機
<host name="www.0431.la" debug="0" appbase="c:\0431la" unpackwars="true" autodeploy="true">
<context path="" docbase="c:\0431la" debug="0" reloadable="true"/>
</host>
10.在iis下面配置虛擬主機的映射目錄
并添加jakarta虛擬目錄 和 isapi篩選 配置過程可參考第五步
11.修改配置文件
c:\program files\apache software foundation\jakarta isapi redirector\conf\uriworkermap.properties
# uriworkermap.properties - iis
#
# this file provides sample mappings for example wlb
# worker defined in workermap.properties.minimal
# the general syntax for this file is:
# [url]=[worker name]
/admin/*=wlb
/manager/*=wlb
/jsp-examples/*=wlb
/servlets-examples/*=wlb
# optionally filter out all .jpeg files inside that context
# for no mapping the url has to start with exclamation (!)
!/servlets-examples/*.jpeg=wlb
#
# mount jkstatus to /jkmanager
# for production servers you will need to
# secure the access to the /jkmanager url
#
/jkmanager=jkstatus
/0431la/*=wlb
/*.jsp=wlb
讓jsp請求交由tomcat處理
呵呵
重啟iis 和 tomcat 看看我們的成果
我們可以考但jsp請求完全正常解析了。
<%@ page language="java" import="java.util.*" pageencoding="iso-8859-1"%>
<%
string path = request.getcontextpath();
string basepath = request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/";
%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<base href="<%=basepath%>" rel="external nofollow" >
<title>my jsp 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" >
-->
</head>
<body>
this is my jsp page. <br>
</body>
</html>
該jsp是myeclipse工程自動生成的。