/*
* 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);
}
}
jsp获取参数信息
最新推荐文章于 2024-05-31 17:11:49 发布