Java examples for Servlet JSP:Servlet
get Parameter Value If Not Null Else Get Default Value from HttpServletRequest
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; } }