get Parameter Value If Not Null Else Get Default Value from HttpServletRequest - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

get Parameter Value If Not Null Else Get Default Value from HttpServletRequest

Demo Code


import java.io.File;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class Main{
    public static String getParamValIfNotNullElseGetDefaultVal(
            String paramName, String defaultValue, HttpServletRequest req) {
        String paramVal = req.getParameter(paramName);
        if (paramVal == null || "".equals(paramVal.trim())) {
            paramVal = defaultValue;/*w  w  w  . j  a  va  2s.c o  m*/
        }
        return paramVal;
    }
}

Related Tutorials