(
一) TOMCAT /webapps/ROOT
环境,直接访问servlet
file:
/webapps/ROOT/WEB-INF/classes/p/Hello.class
Web.xml
/ROOT/WEB-INF /web.xml:
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>p.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/newhello</url-pattern>
</servlet-mapping>
url:
http://127.0.0.1:8080/newhello
(二)
TOMCAT /webapps/new
环境,直接访问new
环境的servlet
file:
/webapps/new/WEB-INF/classes/p/Hello.class
Web.xml
/webapps/new WEB-INF/web.xml:
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>p.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/newhello</url-pattern>
</servlet-mapping>
url:
http://127.0.0.1:8080/new/newhello
-----------------------------------------------------
(
三) TOMCAT /webapps/new
环境,使用server.xml
设置新的环境,通过虚拟路径间接访问new
环境的servlet
/conf/server.xml
<Context path="/n" docBase="/new" debug="0" reloadable="true">
</Context>
file:
/webapps/new/WEB-INF/classes/p/Hello.class
Web.xml
/webapps/new/WEB-INF/web.xml
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>p.Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/newhello</url-pattern>
</servlet-mapping>
url:
http://127.0.0.1:8080/n/newhello
(
四) TOMCAT /webapps/new
环境,使用server.xml
设置新的环境,JSP
通过通过虚拟路径间接访问new
环境的servlet
/conf/server.xml
<Context path="/n" docBase="/new" debug="0" reloadable="true">
</Context>
file:
/webapps/new/givenumber1.jsp
<FORM action="/new/sqrt1" method=get>
<Input Type=text name=number>
<Input Type=submit value="提交">
</FORM>
/webapps/new/WEB-INF/classes/Sqrt.class
web.xml
/webapps/new/WEB-INF/web.xml
(/webapps/new/WEB-INF/web.xml )
<servlet>
<servlet-name>sqrt</servlet-name>
<servlet-class>Sqrt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sqrt</servlet-name>
<url-pattern>/sqrt1</url-pattern>
</servlet-mapping>
url:
http://127.0.0.1:8080/n/givenumber1.jsp
(
五)
设置新的环境,JSP
通过通过虚拟路径间接访问任意环境的servlet
1.工作文件脱离tomcat的环境,自主任意设置存储空间
2.使用server.xml设置新的环境,通过JSP访问设定环境的servlet
/conf/server.xml
<Context path="/n1" docBase="c:/new1" debug="0" reloadable="true">
</Context>
file:
C:/new1/givenumber2.jsp
<FORM action="/n1/sqrt2" method=post>
<Input Type=text name=number>
<Input Type=submit value="提交">
</FORM>
C:/new1/WEB-INF/classes/Sqrt.class
web.xml
C:/new1/WEB-INF/web.xml
<servlet>
<servlet-name>sqrt</servlet-name>
<servlet-class>Sqrt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>sqrt</servlet-name>
<url-pattern>/sqrt2</url-pattern>
</servlet-mapping>
url:
http://127.0.0.1:8080/n1/givenumber2.jsp
---------------------------------------------------------