Java Code Examples for javax.servlet.http.HttpServletRequest.getParameterNames()

The following are Jave code examples for showing how to use getParameterNames() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: tomcat7   File: TestRequest.java   View Source Code Vote up 7 votes
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    req.setCharacterEncoding("UTF-8");

    if (req.getRequestURI().endsWith("parseParametersBeforeParseParts")) {
        req.getParameterNames();
    }

    req.getPart("part");

    resp.setContentType("text/plain");
    resp.setCharacterEncoding("UTF-8");

    resp.getWriter().println("Part " + req.getParameter("part"));
}
 
Example 2
Project: openNaEF   File: ForwarderServlet.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
private HttpMethod createGetMethod(HttpServletRequest req, String uri) throws ServletException,
        NotLoggedInException {

    GetMethod get = new GetMethod(uri);
    addUserNameToHeader(get, req);
    addAcceptEncodingHeader(get, req);

    get.getParams().setContentCharset("UTF-8");
    HttpMethodParams params = new HttpMethodParams();
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String paramName = (String) e.nextElement();
        for (String value : req.getParameterValues(paramName)) {
            params.setParameter(paramName, value);
        }
    }
    get.setParams(params);
    return get;
}
 
Example 3
Project: sdirobot   File: Enter.java   View Source Code Vote up 6 votes
/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        if(sc==null)
       {
           sc = getServletConfig();
            if(sc!=null) init(sc);
       }
    

        Map<String, String> __params = new HashMap<String, String>();
        Enumeration __e = request.getParameterNames();
        while (__e.hasMoreElements()) {
            String tField = __e.nextElement().toString();
            __params.put(tField, request.getParameter(tField));
        }
        __params.put("contextpath", request.getContextPath());
        String __result=getResponce(__params);
        out.println(__result);
    } finally {  
        out.flush();
        out.close();
    }
}
 
Example 4
Project: apache-tomcat-7.0.73-with-comment   File: TestRequest.java   View Source Code Vote up 6 votes
/**
 * Only interested in the parameters and values for POST requests.
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    // Just echo the parameters and values back as plain text
    resp.setContentType("text/plain");

    PrintWriter out = resp.getWriter();

    // Assume one value per attribute
    Enumeration<String> names = req.getParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        out.println(name + "=" + req.getParameter(name));
    }
}
 
Example 5
Project: openNaEF   File: ForwarderServlet.java   View Source Code Vote up 6 votes
private HttpMethod createPostMethod(HttpServletRequest req, String redirectUrl) throws ServletException,
        NotLoggedInException {
    PostMethod post = new PostMethod(redirectUrl);
    addUserNameToHeader(post, req);
    addAcceptEncodingHeader(post, req);

    post.getParams().setContentCharset("UTF-8");
    List<NameValuePair> pairs = new ArrayList<NameValuePair>();
    @SuppressWarnings("unchecked")
    Enumeration e = req.getParameterNames();
    while (e.hasMoreElements()) {
        String paramName = (String) e.nextElement();
        String[] values = req.getParameterValues(paramName);
        for (String value : values) {
            NameValuePair pair = new NameValuePair(paramName, value);
            pairs.add(pair);
        }
    }
    post.addParameters(pairs.toArray(new NameValuePair[0]));
    return post;
}
 
Example 6
Project: Burst   File: WebLogAspect.java   View Source Code Vote up 6 votes
@Before("webLog()")
public void doBefore(JoinPoint joinPoint){
    log.info("------------日志开始:"+LocalDateTime.now()+"------------");
    startTime.set(System.currentTimeMillis());
    // 接收到请求,记录请求内容
    log.info("WebLogAspect.doBefore()");
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // 记录下请求内容
    log.info("URL : " + request.getRequestURL().toString());
    log.info("HTTP_METHOD : " + request.getMethod());
    log.info("IP : " + request.getRemoteAddr());
    log.info("CLASS_METHOD : " + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());
    log.info("ARGS : " + Arrays.toString(joinPoint.getArgs()));
    //获取所有参数方法一:
    Enumeration enu=request.getParameterNames();
    while(enu.hasMoreElements()){
        String paraName=(String)enu.nextElement();
        log.info("PARAM :"+"("+paraName+" : "+request.getParameter(paraName)+")");
    }
}
 
Example 7
Project: rure   File: RequestUtil.java   View Source Code Vote up 6 votes
/**
 * 移除request指定参数
 * @param request
 * @param paramName
 * @return
 */
public String removeParam(HttpServletRequest request, String paramName) {
	String queryString = "";
	Enumeration keys = request.getParameterNames();
	while (keys.hasMoreElements()) {
		String key = (String) keys.nextElement();
		if (key.equals(paramName)) {
			continue;
		}
		if (queryString.equals("")) {
			queryString = key + "=" + request.getParameter(key);
		} else {
			queryString += "&" + key + "=" + request.getParameter(key);
		}
	}
	return queryString;
}
 
Example 8
Project: iosched-reader   File: BaseServlet.java   View Source Code Vote up 6 votes
protected String getParameter(HttpServletRequest req, String parameter)
    throws ServletException {
  String value = req.getParameter(parameter);
  if (value == null || value.trim().isEmpty()) {
    if (DEBUG) {
      StringBuilder parameters = new StringBuilder();
      @SuppressWarnings("unchecked")
      Enumeration<String> names = req.getParameterNames();
      while (names.hasMoreElements()) {
        String name = names.nextElement();
        String param = req.getParameter(name);
        parameters.append(name).append("=").append(param).append("\n");
      }
      logger.fine("parameters: " + parameters);
    }
    throw new ServletException("Parameter " + parameter + " not found");
  }
  return value.trim();
}
 
Example 9
Project: jerrydog   File: CGIProcessEnvironment.java   View Source Code Vote up 6 votes
/**
 * Creates a ProcessEnvironment and derives the necessary environment,
 * working directory, command, etc.
 * @param req             HttpServletRequest for information provided by
 *                        the Servlet API
 * @param context         ServletContext for information provided by
 *                        the Servlet API
 * @param cgiPathPrefix   subdirectory of webAppRootDir below which the
 *                        web app's CGIs may be stored; can be null or "".
 * @param  debug          int debug level (0 == none, 6 == lots)
 */
public CGIProcessEnvironment(HttpServletRequest req,
    ServletContext context, String cgiPathPrefix, int debug) {
        super(req, context, debug);
        this.cgiPathPrefix = cgiPathPrefix;
        queryParameters = new Hashtable();
        Enumeration paramNames = req.getParameterNames();
        while (paramNames != null && paramNames.hasMoreElements()) {
            String param = paramNames.nextElement().toString();
            if (param != null) {
                queryParameters.put(param,
                    URLEncoder.encode(req.getParameter(param)));
            }
        }
        this.valid = deriveProcessEnvironment(req);
}
 
Example 10
Project: swallow-core   File: RequestHelper.java   View Source Code Vote up 6 votes
/**
 * 将请求参数封装到SearchFilter
 * @param request javax.servlet.http.HttpServletRequest
 * @see SearchFilter
 * @return SearchFilter
 */
static SearchFilter getSearchFilter(HttpServletRequest request) {
    SearchFilter searchFilter = new SearchFilter();
    Enumeration<String> names = request.getParameterNames();
    while (names.hasMoreElements()) {
        String name = names.nextElement();
        if ("page".equals(name)) {
            searchFilter.setPage(Integer.parseInt(request.getParameter(name)));
            continue;
        }
        if ("rows".equals(name)) {
            searchFilter.setRows(Integer.parseInt(request.getParameter(name)));
            continue;
        }
        searchFilter.addParam(name, request.getParameter(name));
    }
    return searchFilter;
}
 
Example 11
Project: ureport   File: BaseServletAction.java   View Source Code Vote up 6 votes
protected Map<String, Object> buildParameters(HttpServletRequest req) {
	Map<String,Object> parameters=new HashMap<String,Object>();
	Enumeration<?> enumeration=req.getParameterNames();
	while(enumeration.hasMoreElements()){
		Object obj=enumeration.nextElement();
		if(obj==null){
			continue;
		}
		String name=obj.toString();
		String value=req.getParameter(name);
		if(name==null || value==null || name.startsWith("_")){
			continue;
		}
		parameters.put(name, decode(value));
	}
	return parameters;
}
 
Example 12
Project: mxhsd   File: DefaultClientController.java   View Source Code Vote up 5 votes
@RequestMapping("/**")
public String catchAll(HttpServletRequest req, HttpServletResponse res) {
    log(req);

    StringBuffer postData = new StringBuffer();
    Enumeration<String> postParms = req.getParameterNames();
    while (postParms.hasMoreElements()) {
        String parm = postParms.nextElement();
        if ("access_token".equals(parm.toLowerCase())) {
            postData.append(parm).append("=").append("<redacted>");
        } else {
            if (postData.length() > 0) {
                postData.append("&");
            }
            postData.append(parm).append("=").append(req.getParameter(parm));
        }
    }

    log.debug("Unsupported URL: {} {}", req.getMethod(), req.getRequestURL());
    if (postData.length() > 0) {
        log.debug("POST data: {}", postData);
    }
    try {
        log.debug("Body: {}", IOUtils.toString(req.getInputStream(), StandardCharsets.UTF_8));
    } catch (IOException e) {
        log.debug("Body: Unable to read", e);
    }

    res.setStatus(HttpServletResponse.SC_NOT_FOUND);
    return DefaultExceptionHandler.handle("M_NOT_IMPLEMENTED", "Not implemented");
}
 
Example 13
Project: shop-manager   File: SqlFilter.java   View Source Code Vote up 5 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response,
		FilterChain chain) throws IOException, ServletException {
	HttpServletRequest req = (HttpServletRequest) request;    
       HttpServletResponse res = (HttpServletResponse) response;    
       //获得所有请求参数名    
       @SuppressWarnings("rawtypes")  
       Enumeration params = req.getParameterNames();    
   
       String sql = "";    
       while (params.hasMoreElements()) {    
           //得到参数名    
           String name = params.nextElement().toString();    
           //System.out.println("name===========================" + name + "--");    
           //得到参数对应值    
           String[] value = req.getParameterValues(name);    
           for (int i = 0; i < value.length; i++) {    
               sql = sql + value[i];    
           }    
       }    
       //System.out.println("============================SQL"+sql);    
       //有sql关键字,跳转到error.html    
       if (sqlValidate(sql)) {    
           res.sendRedirect("error.html");    
           //String ip = req.getRemoteAddr();    
       } else {    
           chain.doFilter(req, res);    
       }    
}
 
Example 14
Project: iBase4J-Common   File: UploadUtil.java   View Source Code Vote up 5 votes
public static List<String> uploadImageData(HttpServletRequest request) {
    List<String> fileNames = InstanceUtil.newArrayList();
    Enumeration<String> params = request.getParameterNames();
    String pathDir = getUploadDir(request);
    File dir = new File(pathDir);
    if (!dir.exists()) {
        dir.mkdirs();
    }
    while (params.hasMoreElements()) {
        String key = params.nextElement();
        String fileStr = request.getParameter(key);
        if (fileStr != null && !"".equals(fileStr)) {
            int index = fileStr.indexOf("base64");
            if (index > 0) {
                try {
                    String fileName = UUID.randomUUID().toString();
                    String preStr = fileStr.substring(0, index + 7);
                    String prefix = preStr.substring(preStr.indexOf("/") + 1, preStr.indexOf(";")).toLowerCase();
                    fileStr = fileStr.substring(fileStr.indexOf(",") + 1);
                    byte[] bb = Base64.getDecoder().decode(fileStr);
                    for (int j = 0; j < bb.length; ++j) {
                        if (bb[j] < 0) {// 调整异常数据
                            bb[j] += 256;
                        }
                    }
                    String distPath = pathDir + fileName + "." + prefix;
                    OutputStream out = new FileOutputStream(distPath);
                    out.write(bb);
                    out.flush();
                    out.close();
                    fileNames.add(fileName + "." + prefix);
                } catch (Exception e) {
                    logger.error("上传文件异常:", e);
                }
            }
        }
    }
    return fileNames;
}
 
Example 15
Project: azeroth   File: RequestUtils.java   View Source Code Vote up 5 votes
protected static Map<String, Object> buildQueryParamsMap(HttpServletRequest request) {

        Map<String, Object> params = new HashMap<String, Object>();
        Enumeration<String> e = request.getParameterNames();

        StringBuilder tmpbuff = new StringBuilder();
        if (e.hasMoreElements()) {
            while (e.hasMoreElements()) {
                String name = e.nextElement();
                String[] values = request.getParameterValues(name);
                if (values.length == 1) {
                    if (StringUtils.isNotBlank(values[0]))
                        params.put(name, values[0]);
                } else {
                    tmpbuff.setLength(0);
                    for (int i = 0; i < values.length; i++) {
                        if (StringUtils.isNotBlank(values[i])) {
                            tmpbuff.append(values[i].trim()).append(",");
                        }
                    }
                    if (tmpbuff.length() > 0) {
                        tmpbuff.deleteCharAt(tmpbuff.length() - 1);
                        params.put(name, tmpbuff.toString());
                    }
                }
            }
        }
        return params;
    }
 
Example 16
Project: EatDubbo   File: ParameterMap.java   View Source Code Vote up 5 votes
@SuppressWarnings("unchecked")
public ParameterMap(HttpServletRequest request, Context context, TurbineRunDataInternal navigator){
    super();
    this.request = request;
    this.context = context;
    this.rundata = navigator;
    Enumeration<String> keys = request.getParameterNames();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        Object value = getParameterValue(key);
        context.put(key, value);
    }
}
 
Example 17
Project: lams   File: ImplicitObjectELResolver.java   View Source Code Vote up 5 votes
/**
 *
 * Creates the Map that maps parameter name to single parameter
 * value.
 **/
public static Map<String, String> createParamMap (PageContext pContext)
{
  final HttpServletRequest request =
    (HttpServletRequest) pContext.getRequest ();
  return new EnumeratedMap<String, String> ()
    {
      public Enumeration<String> enumerateKeys () 
      {
        return request.getParameterNames ();
      }

      public String getValue (Object pKey) 
      {
        if (pKey instanceof String) {
          return request.getParameter ((String) pKey);
        }
        else {
          return null;
        }
      }

      public boolean isMutable ()
      {
        return false;
      }
    };
}
 
Example 18
Project: backside-servlet-ks   File: BaseHandler.java   View Source Code Vote up 4 votes
/**
     * <p>Paths that come in without a trailing '/' can be null</p>
     * @param request
     * @return
     * @throws ServletException
     */
    public String getPath(HttpServletRequest request) throws ServletException {
    	String path = notNullString(request.getPathInfo()).trim();
//    	System.out.println("FOO "+path);
//    	System.out.println("QUERY "+this.getQueryString(request));
//    	System.out.println("DATA "+request.getParameter("data"));
//    	System.out.println("LENGTH "+request.getContentLength());
    	//Enumeration<String> ex = request.getHeaderNames();
    	Enumeration<String> ex = request.getParameterNames();
    	if (ex != null) {
    		List<String>l = new ArrayList<String>();
    		while (ex.hasMoreElements())
    			l.add(ex.nextElement());
    		//System.out.println("HEADERNAMES "+l);
    		//HEADERNAMES [Origin, Accept, Connection, User-Agent, Referer, Host, DNT, Accept-Encoding, Accept-Language, Content-Length, Content-Type]
    		//That was no help
 //   		System.out.println("PARAMNAMES "+l);
    		//PARAMNAMES [{"verb":"Auth","uEmail":"joe","uPwd":"joe"}]
    		// the first one is our data
    	}
    	
    	try {
    		InputStream ins = request.getInputStream();
    		if (ins != null) {
    			StringBuilder buf = new StringBuilder();
    			int c;
    			while ((c = ins.read()) > -1)
    				buf.append((char)c);
        		System.out.println(buf.toString());
    			
    		}
    	} catch (Exception x) {
    		System.out.println("BaseHandler.getPath booboo "+x.getMessage());
    	}
    	if (path.startsWith("/"))
    		path = path.substring(1);
    	if (path.endsWith("/"))
    		path = path.substring(0,path.length()-1);
    	try {
    		path = URLDecoder.decode(path, "UTF8");
    	} catch (Exception e) {
    		throw new ServletException(e);
    	}
    	if (path != null && path.startsWith("/"))
    		path = path.substring(1);
    	System.out.println(path);
    	return path;
    }
 
Example 19
Project: hadoop-oss   File: ReconfigurationServlet.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
private Enumeration<String> getParams(HttpServletRequest req) {
  return req.getParameterNames();
}
 
Example 20
Project: iBase4J-Common   File: XssFilter.java   View Source Code Vote up 4 votes
public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
    throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest)arg0;
    HttpServletResponse response = (HttpServletResponse)arg1;
    String pathInfo = req.getPathInfo() == null ? "" : req.getPathInfo();
    String url = req.getServletPath() + pathInfo;
    String uri = req.getRequestURI();
    boolean isNoticeUrl = false;
    // 排除部分URL不做过滤。
    for (String str : excludeUrls) {
        if (uri.indexOf(str) >= 0) {
            logger.info("该URL不作校验:" + url);
            arg2.doFilter(req, response);
            return;
        }
    }
    for (String st : noticeUrls) {
        if (uri.indexOf(st) >= 0) {
            isNoticeUrl = true;
            break;
        }
    }
    // 获取请求所有参数,校验防止SQL注入,防止XSS漏洞

    Enumeration<?> params = req.getParameterNames();
    String paramN = null;
    while (params.hasMoreElements()) {
        paramN = (String)params.nextElement();
        String paramVale = req.getParameter(paramN);
        if (!paramN.toLowerCase().contains("password")) {
            logger.info(paramN + "==" + paramVale);
        }
        if (isNoticeUrl) {
            paramVale = xssEncode(paramVale);
        }
        // 校验是否存在SQL注入信息
        if (checkSQLInject(paramVale, url)) {
            errorResponse(response, paramN);
            return;
        }
    }
    arg2.doFilter(req, response);
}