Idea中修改servlet模板

1.点击左上角的File: Setting --> Editor --> File and Code Templates --> Other --> web -->Servlet Annotated Class.java

模板代码:

#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#parse("File Header.java")
/**
 * @Description TODO
 * @ClassName ${Class_Name}
 * @Author 悦文
 * @Date ${DATE} ${TIME}
 * @Version V1.0
 */
@javax.servlet.annotation.WebServlet(name = "${Entity_Name}", urlPatterns="/${Entity_Name}")
public class ${Class_Name} extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
    request.setCharacterEncoding("utf-8");// 处理post请求乱码问题
    response.setContentType("text/html;charset=utf-8"); // 处理响应乱码问题:字节流需getBytes("UTF-8")
        
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
    
doPost(request,response);
//response.setContentType("text/html;charset=UTF-8"); // 处理响应乱码问题:字节流需getBytes("UTF-8")
// str = new String(str.getBytes("ISO-8859-1"), "UTF-8");   // 处理get请求乱码问题
    }
}

 

posted @ 2018-11-30 10:40  悦文  阅读(4331)  评论(1编辑  收藏  举报