List of usage examples for javax.servlet.http HttpServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java
public static String getParameter(final HttpServletRequest req, final String parameterName, final String defaultValue) { final String result = req.getParameter(parameterName); return result != null ? result : defaultValue; }
From source file:com.enonic.cms.web.portal.instanttrace.InstantTraceRequestInspector.java
public static boolean isAuthenticationSubmitted(final HttpServletRequest request) { if (!"POST".equalsIgnoreCase(request.getMethod())) { return false; }//from ww w . java 2 s .co m String userName = request.getParameter("_itrace_username"); String password = request.getParameter("_itrace_password"); if (userName != null && password != null) { return true; } return false; }
From source file:com.mmd.mssp.util.WebUtil.java
public static String getHttpQueryParam(HttpServletRequest request, String key) throws UnsupportedEncodingException { String val, ie = request.getParameter("ie"); String ua = request.getHeader("User-Agent"); if (ua != null && ua.contains("MSIE")) {//IE GBK ? if (ie != null) { try { val = WebUtil.getHttpQueryParam(request, key, ie); } catch (UnsupportedEncodingException ex) { val = WebUtil.getHttpQueryParam(request, key, "UTF-8"); }/*from w ww. ja v a 2s.c o m*/ } else { val = WebUtil.getHttpQueryParam(request, key, "GBK"); } } else { val = WebUtil.getHttpQueryParam(request, key, "UTF-8"); } request.setAttribute("QueryValue", val); // val = val.replaceAll("\\\\", "\\\\\\\\").replaceAll("%", "\\\\%").replaceAll("_", "\\\\_"); return val; }
From source file:common.web.controller.CommonActions.java
/** * executes an update, serves as a template method that incapsulates common logic for insert action * @param service/*from ww w .j a v a 2 s . co m*/ * @param config * @param val for validation * @param req resulting model (i.e. errors, command objects ...) will be placed here */ public static <T> boolean doInsert(IInsertService<T> service, IControllerConfig config, ABindValidator val, HttpServletRequest req) { String action = req.getParameter(ControllerConfig.ACTION_PARAM_NAME); T command = service.getInsertBean(); RequestUtils.copyRequestAttributesFromMap(req, service.initInsert()); if ("insert".equals(action)) { /** bind command */ BindingResult res = val.bindAndValidate(command, req); if (res.hasErrors() || !service.insert(command)) { //m.putAll(res.getModel()); req.setAttribute(res.MODEL_KEY_PREFIX + config.getContentDataAttribute(), res); req.setAttribute(config.getContentDataAttribute(), command); common.CommonAttributes.addErrorMessage("form_errors", req); return false; } else { //req.setAttribute(config.getContentDataAttribute(), service.getInsertBean()); req.setAttribute(config.getContentDataAttribute(), command); common.CommonAttributes.addHelpMessage("operation_succeed", req); } } else { //val.bindAndValidate(command, req); req.setAttribute(config.getContentDataAttribute(), command); } return true; }
From source file:dk.netarkivet.harvester.webinterface.HarvestChannelAction.java
/** * This method processes the request to determine which action it corresponds to and passes the request along * accordingly. Available actions are://from w w w . j a v a 2s.c o m * <ul> * <li>create harvest channel</li> * <li>map harvest definition to channel</li> * </ul> * * @param context the original servlet context of the request. * @param i18n the internationalisation to be used. * @throws ForwardedToErrorPage if an exception is thrown while carrying out the action. */ public static void processRequest(PageContext context, I18n i18n) throws ForwardedToErrorPage { ArgumentNotValid.checkNotNull(context, "PageContext context"); ArgumentNotValid.checkNotNull(i18n, "I18n i18n"); log.debug("Processing request"); HttpServletRequest request = (HttpServletRequest) context.getRequest(); try { String action = request.getParameter(ACTION); if (action == null || action.isEmpty()) { return; } switch (ActionType.valueOf(action)) { case createHarvestChannel: String name = request.getParameter(CHANNEL_NAME); HTMLUtils.forwardOnEmptyParameter(context, CHANNEL_NAME); HarvestChannelDAO dao = HarvestChannelDAO.getInstance(); dao.create(new HarvestChannel(name, false, false, request.getParameter(COMMENTS))); break; case mapHarvestToChannel: long harvestId = Long.parseLong(request.getParameter(HARVEST_ID)); long channelId = Long.parseLong(request.getParameter(CHANNEL_ID)); HarvestChannelDAO hcDao = HarvestChannelDAO.getInstance(); HarvestDefinitionDAO hdDao = HarvestDefinitionDAO.getInstance(); hdDao.mapToHarvestChannel(harvestId, hcDao.getById(channelId)); break; default: } } catch (Throwable e) { HTMLUtils.forwardWithErrorMessage(context, i18n, e, "errormsg;harvest.channel.create.error"); throw new ForwardedToErrorPage("Error in Harvest Channels", e); } }
From source file:net.sf.appstatus.web.pages.Resources.java
public static void doGet(StatusWebHandler webHandler, HttpServletRequest req, HttpServletResponse resp) throws IOException { String location = null;//from w w w. j a v a2s . co m String id = req.getParameter("resource"); if (id == null) { id = req.getParameter("icon"); } if (resources.containsKey(id)) { resp.setContentType(resources.get(id).getMimeType()); location = resources.get(id).getLocation(); InputStream is = Resources.class.getResourceAsStream(location); IOUtils.copy(is, resp.getOutputStream()); } else { resp.sendError(404); } }
From source file:com.buession.cas.web.utils.CaptchaUtils.java
/** * ???/*from w ww .j ava2 s .c om*/ * * @param request * HttpServletRequest * @param requestParamName * ????? * @param config * ??? * @return ??? */ public static boolean validate(final HttpServletRequest request, final String requestParamName, final Config config) { String value = request .getParameter(requestParamName == null ? REQUEST_CAPTCHA_PARAM_NAME : requestParamName); return validate(request, config, value); }
From source file:com.bluexml.side.Framework.alfresco.shareLanguagePicker.CustomDispatcherServlet.java
public static void setLanguageFromLayoutParam(HttpServletRequest req) { String urlLang = req.getParameter("shareLang"); HttpSession currentSession = req.getSession(); String sessionLang = (String) currentSession.getAttribute("shareLang"); //1st option: Select the url param shareLang if (urlLang != null) { I18NUtil.setLocale(I18NUtil.parseLocale(urlLang)); currentSession.setAttribute("shareLang", urlLang); } else if (sessionLang != null) { I18NUtil.setLocale(I18NUtil.parseLocale(sessionLang)); } else {//from w w w . j ava 2 s .co m // set language locale from browser header String acceptLang = req.getHeader("Accept-Language"); if (acceptLang != null && acceptLang.length() != 0) { StringTokenizer t = new StringTokenizer(acceptLang, ",; "); // get language and convert to java locale format String language = t.nextToken().replace('-', '_'); I18NUtil.setLocale(I18NUtil.parseLocale(language)); } } }
From source file:com.asual.summer.core.RequestFilter.java
static String getMethod(HttpServletRequest request, String requestMethod) { String method = request.getParameter(methodAttribute); if ("POST".equalsIgnoreCase(requestMethod) && !StringUtils.isEmpty(method)) { return method.toUpperCase(Locale.ENGLISH); }/* w ww . ja v a2s .co m*/ return requestMethod; }
From source file:com.linuxbox.enkive.web.AuditLogServlet.java
private static String cleanGetParameter(HttpServletRequest request, String parameterName) { String parameterValue = request.getParameter(parameterName); if (parameterValue == null || parameterValue.equalsIgnoreCase("null")) { return null; } else {/*from ww w . j a va 2s . c o m*/ return parameterValue; } }