About some common mistakes in Servlet

1: There are generally two solutions to the problem of page garbled characters:

The problem of garbled servlet output:
response.setCharacterEncoding("utf-8");

request.setCharacterEncoding("UTF-8");

2: Servlet. Unlike the built-in object that has a session in a jsp page, it is generally necessary to declare it first, such as:

Httpsession session=request.getSession(), the same application cannot be used directly, it should be

ServletContext application=this.getServletContext() can only be used

3: Generally, it is not necessary to redirect to a certain page after transferring data, but forwarding should be used. (for convenience)

4: servlet: Method 1: To inherit HttpServlet

  To return html in the servlet, set response.setContentType("text/html");  


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325734600&siteId=291194637