返回结果乱码问题
public class GetServletContext extends HttpServlet{
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html; charset=UTF-8");
ServletContext servletContext = this.getServletContext();
String username = (String)servletContext.getAttribute("username");
PrintWriter writer = resp.getWriter();
writer.print("获取的用户名:"+username);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}