zoukankan      html  css  js  c++  java
  • Request中的方法调用

    几种方法的调用:

    package com.stono.servlet;
    
    import java.io.IOException;
    import java.util.Enumeration;
    import javax.servlet.ServletException;
    import javax.servlet.http.Cookie;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class TestServlet2 extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
                IOException {
            System.out.println("do get method called!");
        }
    
        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
                IOException {
            String method = req.getMethod();
            System.out.println("method is " + method);
            Enumeration<String> headerNames = req.getHeaderNames();
            int i = 0;
            while (headerNames.hasMoreElements()) {
                String nextElement = headerNames.nextElement();
                String header = req.getHeader(nextElement);
                System.out.println(++i + ":" + nextElement + ":" + header);
            }
            System.out.println("===============COOKIE================");
            Cookie[] cookies = req.getCookies();
            for (Cookie cookie : cookies) {
                System.out.println(cookie);
                cookie.getName();
                cookie.getValue();
                cookie.getVersion();
            }
            System.out.println("================Remote===================");
            String remoteAddr = req.getRemoteAddr();
            String remoteHost = req.getRemoteHost();
            int remotePort = req.getRemotePort();
            String remoteUser = req.getRemoteUser();
            System.out.println(remoteAddr);
            System.out.println(remoteHost);
            System.out.println(remotePort);
            System.out.println(remoteUser);
            System.out.println("================Server===================");
            String serverName = req.getServerName();
            int serverPort = req.getServerPort();
            String servletPath = req.getServletPath();
            System.out.println(serverName);
            System.out.println(serverPort);
            System.out.println(servletPath);
            System.out.println("================Local===================");
            String localAddr = req.getLocalAddr();
            String localName = req.getLocalName();
            int localPort = req.getLocalPort();
            System.out.println(localAddr);
            System.out.println(localName);
            System.out.println(localPort);
            
            System.out.println("do post method called");
            String[] strings = req.getParameterValues("txt1");
            System.out.println(strings.length);
            for (String string : strings) {
                System.out.println(string);
            }
        }
    }
  • 相关阅读:
    css实现截取文本
    ob_clean()解决php验证码图片无法显示
    JS获取url参数,修改url参数
    mysql模糊查询特殊字符(\,%和_)处理
    apache反向代理和监听多个端口设置
    页面底部自适应浏览器窗口高度
    变量相关考虑
    php非法输入数据类型
    php socket模拟http中post或get提交数据
    华为专利的 hybrid 端口
  • 原文地址:https://www.cnblogs.com/stono/p/4831234.html
Copyright © 2011-2022 走看看