Javaweb关于web.xml的相关配置信息
Javaweb关于web.xml的相关配置信息
初始页面
<!-- 规定加载进入的初始页面-->
<welcome-file-list>
<welcome-file>/login.jsp</welcome-file>
</welcome-file-list>
配置Servlet
<!--配置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>
过滤器
<!--过滤器-->
<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>
配置乱码的公共参数
<!-- 配置公共参数 -->
<context-param>
<param-name>charEncoding</param-name>
<param-value>utf-8</param-value>
</context-param>
//定义编码
private String bm = "";
//Servlet初始化编码
@Override
public void init(ServletConfig config) throws ServletException {
bm = config.getServletContext().getInitParameter("charEncoding");
}
//config.getServletContext() 获取xml中配置的公共参数
private String character = "GBK";
//Filter初始化编码
@Override
public void init(FilterConfig filterConfig) throws ServletException {
character = filterConfig.getServletContext().getInitParameter("charEncoding");
}
原文地址:https://blog.csdn.net/weixin_62008675/article/details/144018089
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!