jsp获取参数信息

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Administrator
 */
public class BaseServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	System.out.println("doget");
    	doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //
        StringBuffer sb = new StringBuffer();
        response.setHeader("Content-Type", "text/html;charset=UTF-8");
        request.getSession().setAttribute("admin", "admin");
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                sb.append("cookie:"+cookie.getName() + "," + cookie.getValue());
            }
        }
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        String uri = request.getRequestURI();
        String method = request.getMethod();
        response.setHeader("Content-Type", "text/html;charset=UTF-8");
        Map<String, String[]> maps = request.getParameterMap();
        //System.out.println(TypeUtil.typeToString("maps", maps));
        Set<Map.Entry<String, String[]>> entrys = maps.entrySet();
        for (Map.Entry<String, String[]> entry : entrys) {
            String key = entry.getKey();
            String[] values = entry.getValue();
            sb.append(key + "=");
            for (String string : values) {
                sb.append(string + ",");
            }
        }
        sb.append(",ip=" + ip + ",uri=" + uri + ",method=" + method);
        response.getWriter().print(sb.toString());
        System.out.println(sb.toString());
       // super.doPost(request, response);
    }

    @Override
    protected void service(HttpServletRequest hsr, HttpServletResponse hsr1) throws ServletException, IOException {
        super.service(hsr, hsr1);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值