web项目中如何设置web.xml文件

2025-10-15 20:42:01

1、<display-name>ZHCity</display-name>,在<display-name>中设置需要显示的项目名称

web项目中如何设置web.xml文件

2、<context-param>

<param-name>contextConfigLocation</param-name>

<param-value>classpath:spring/ApplicationContext.xml</param-value>

</context-param>

在其中配置spring框架的spring配置文件

web项目中如何设置web.xml文件

3、<context-param>

<param-name>log4jConfigLocation</param-name>

<param-value>classpath:log4j.properties</param-value>

</context-param>

配置日志,方便在项目启动的时候记录日志。

web项目中如何设置web.xml文件

4、<init-param>

<param-name>encoding</param-name>

<param-value>utf-8</param-value>

</init-param>

配置过滤器,设置为utf-8的格式,使得在不同的浏览器中汉字不会出现乱码。

web项目中如何设置web.xml文件

5、<filter-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

配置拦截器需要拦截的url,/*表示需要拦截所有的路径。

web项目中如何设置web.xml文件

6、<error-page>

<error-code>404</error-code>

<location>/404.jsp</location>

</error-page>

配置一个通用的页面出来地址,方便在出现错误 的时候跳转至统一的界面。

web项目中如何设置web.xml文件

声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢