Javaweb关于web.xml的相关配置信息
初始页面
xml
<!-- 规定加载进入的初始页面-->
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
配置Servlet
xml
<!--配置Servlet-->
<servlet>
<servlet-name>UserLoginServlet</servlet-name>
<servlet-class>com.hz.servlet.UserLoginServlet</servlet-class>
<!-- 启动tomcat就加载Servlet-->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>UserLoginServlet</servlet-name>
<url-pattern>/userLoginServlet</url-pattern>
</servlet-mapping>
过滤器
xml
<!--过滤器-->
<filter>
<filter-name>charEnCoding</filter-name>
<filter-class>com.hz.filter.CharEnCodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>charEnCoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
配置乱码的公共参数
xml
<!-- 配置公共参数 -->
<context-param>
<param-name>charEncoding</param-name>
<param-value>utf-8</param-value>
</context-param>
java
//定义编码
private String bm = "";
//Servlet初始化编码
@Override
public void init(ServletConfig config) throws ServletException {
bm = config.getServletContext().getInitParameter("charEncoding");
}
//config.getServletContext() 获取xml中配置的公共参数
java
private String character = "GBK";
//Filter初始化编码
@Override
public void init(FilterConfig filterConfig) throws ServletException {
character = filterConfig.getServletContext().getInitParameter("charEncoding");
}