• servlet 提交【get post】


    import java.io.IOException;
    import java.io.PrintWriter;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class charset extends HttpServlet {
    
        /**
         * Constructor of the object.
         */
        public charset() {
            super();
        }
    
        /**
         * Destruction of the servlet. <br>
         */
        public void destroy() {
            super.destroy(); // Just puts "destroy" string in log
            // Put your code here
        }
    
        /**
         * The doGet method of the servlet. <br>
         * 
         * This method is called when a form has its tag value method equals to get.
         * 
         * @param request
         *            the request send by the client to the server
         * @param response
         *            the response send by the server to the client
         * @throws ServletException
         *             if an error occurred
         * @throws IOException
         *             if an error occurred
         */
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
           
            // String str = request.getParameter("xh");
            // String str2 = new String(str.getBytes("iso-8859-1"), "utf-8");
            // System.out.println(str);
            // System.out.println(str2);
            //这句话是告诉浏览器 怎么去按照编码解析
            // response.setHeader("Content-type", "text/html;charset=UTF-8");
            // // response.getOutputStream().write(str2.getBytes("utf-8"));
            // response.getWriter().write(str2);
            //告诉servlet 按照编码解析
            //response.setCharacterEncoding("utf-8");
            gettj(request, response);//方法2
        }
    
        /**
         * The doPost method of the servlet. <br>
         * 
         * This method is called when a form has its tag value method equals to
         * post.
         * 
         * @param request
         *            the request send by the client to the server
         * @param response
         *            the response send by the server to the client
         * @throws ServletException
         *             if an error occurred
         * @throws IOException
         *             if an error occurred
         */
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            request.setCharacterEncoding("utf-8");
            String str1 = request.getParameter("xh");
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(str1);
    
        }
    
        /**
         * Initialization of the servlet. <br>
         * 
         * @throws ServletException
         *             if an error occurs
         */
        public void init() throws ServletException {
            // Put your code here
        }
    
        public static void gettj(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {
            response.setHeader("Content-type", "text/html;charset=utf-8");
            String str1 = request.getQueryString();
            String str2 = java.net.URLDecoder.decode(str1, "utf-8");
            String[] arr = str2.split("&");
            for (String str : arr) {
    
                String[] str3 = str.split("=");
                response.getWriter().write(str3[1]);
    
            }
    
        }
    
    }
    View Code

     如果  get表单里面内容多  直接修改tomcat  URLEncoding="utf-8" 

  • 相关阅读:
    数据库 PSU,SPU(CPU),Bundle Patches 和 Patchsets 补丁号码快速参考 (文档 ID 1922396.1)
    从巡检备份失败排查解决数据库故障
    oracle rac自动生成awr
    解决 umount 时出现的 "Device is busy"
    修改sys密码与nbu备份脚本密码后,nbu备份报密码无效
    Oracle_RAC数据库GI的PSU升级(11.2.0.4.0到11.2.0.4.8)
    oracle补丁升级
    AIX上增加逻辑卷时报错误0516-787 extendlv: Maximum allocation for logical volume
    oracle11g dataguard 完全手册
    数据库节点1存储丢失
  • 原文地址:https://www.cnblogs.com/xh0626/p/5515261.html
Copyright © 2020-2023  润新知