get Parameter from HttpServletRequest - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

get Parameter from HttpServletRequest

Demo Code

import java.io.UnsupportedEncodingException;
import java.util.Collection;
import java.util.Map;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;

public class Main{
    public static StringBuilder getParameter(HttpServletRequest request,
            String name, StringBuilder defaultValue) {
        StringBuilder param = new StringBuilder(request.getParameter(name));
        if (param == null || param.toString().equals("")) {
            return defaultValue;
        }// w  w  w  .j  a v  a 2s.c o  m
        return param;
    }
    public static boolean equals(Object obj1, Object obj2) {
        if (obj1 == obj2) {
            return true;
        } else {
            if (obj1 == null || obj2 == null) {
                return false;
            } else if (obj1.toString().equals(obj2)) {
                return true;
            }
            return false;
        }
    }
    public static String toString(Object str) {
        return str == null ? "" : str.toString();
    }
}

Related Tutorials