Debug时已经看到value的值是“张三” ,控制台输出是: ��������@WebServlet("/test")
public class TestServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String value = req.getParameter("value");
System.out.println(value);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doGet(req, resp);
}
}
加了过滤器也没用@WebFilter("/test")
public class WordFilter implements Filter {
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
System.out.println("WebFilter");
//servletRequest.setCharacterEncoding("UTF-8");
filterChain.doFilter(servletRequest,servletResponse);
}
}
加了过滤器后输出也就变成:
WebFilter
��������
补充一下jsp的代码吧<!DOCTYPE html>
<html>
<head>
<title>JSP - Hello World</title>
</head>
<body>
<form action="/test" method="post">
<input type="text" name="value">
<input type="submit" name="submit">
</form>
</body>
</html>
为什么会出现这种事,以及怎么处理? |