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);
        }
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值