Servlet的编码问题
java中默认的是utf-8,而浏览器、tomcat他们默认的编码方式是iso885i9-1如果说不用中文,就用他默认的就行。但是现在我们的需求是用中文显示而且还不乱码。为了防止乱码就应该是用什么方式编码,就用什么方式来解码。
Javaweb解决Servlet编码的方法:
设置请求字符编码,解决客户端提交数据是中文乱码问题
设置必须在request.getParameter(" ") 方法前调用,否则不起作 只针对post请求方式有效,对get请求方式无效 如果解决Get请求乱码问题,需要在Tomcat/conf/server.xml中设置字符编码
request.setCharacterEncoding(“UTF-8”);
服务器端告诉客户端浏览器,返回的是text/html类型的数据
设置响应内容类型及编码,需要在response.getWriter().println("")方法调前设置,否则不起作用
response.setContentType(“text/html;charset=UTF-8”);
解决cvc-complex-type.2.4.a: Invalid content was found starting with element ‘url-patten’. One of ‘{“http://java.sun.com/xml/ns/javaee”:url-pattern, “http://java.sun.com/xml/ns/javaee”:servlet- name}’ is expected.
小红叉的问题:
解决办法为:将“http://www.springmodules.org/schema/cache/springmodules-cache.xsd http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd”这段话加入到xml文件的"xmlns:xsi="的标签中