Javaweb-1 server.xml和web.xml中的配置

来源:互联网 发布:sql执行顺序 编辑:程序博客网 时间:2024/06/05 11:03

server.xml中的配置

1、web项目的发布:

1)在tomcat的webapp目录下有项 目目录时在浏览器中输入 http://local:host/项目名

2)通过context设置虚拟路径

在apache-tomcat-7.0.72\conf 目录下的server.xml中在

<Host name="localhost"  appBase="webapps"  unpackWARs="true" autoDeploy="true">

后增加 

<Contest path="/xxx" docBase="项目路径" reloadable="false"/>

也可以完成.之后通过 http://local:host/xxx访问 

reloadable表示java文件修改后是否自动重新加载


<Connector port="8080" protocol="HTTP/1.1"   connectionTimeout="20000"  redirectPort="8443" />


Connector要用来配置相应的访问属性,port表示访问端口为8080.

80端口为默认可不输


2、host虚拟主机

<Host name="localhost"  appBase="webapps"  unpackWARs="true" autoDeploy="true" name="域名" unpackWARs="true" xmlNamespacaAware="false" xmlValidation="false"> <Contest path="" docBase="项目路径" reloadable="false"/></Host>


<待补完>

再通过DNS服务器,说明链接IP地址和域名的关系。

web.xml中的配置

1、默认访问文件

    <welcome-file-list>        <welcome-file>index.html</welcome-file>        <welcome-file>index.htm</welcome-file>        <welcome-file>index.jsp</welcome-file>    </welcome-file-list>


一般不修改

所以任意一个项目的WEB-INF目录下必须有个index文件(WEB-INF和index文件名都不可修改)

2、

    <servlet>        <servlet-name>default</servlet-name>        <servlet-class>org.apache.catalina.servlets.DefaultServlet</servlet-class>        <init-param>            <param-name>debug</param-name>            <param-value>0</param-value>        </init-param>        <init-param>            <param-name>listings</param-name>            <param-value>false</param-value>        </init-param>        <load-on-startup>1</load-on-startup>    </servlet>


把listing设置为true,在网页端就可以显示文件夹目录


注:1)开发过程中可用,发布时切记关闭

2)WEB-INF目录不可见


0 0
原创粉丝点击