List of usage examples for javax.servlet.jsp PageContext getRequest
abstract public ServletRequest getRequest();
From source file:com.ecyrd.jspwiki.filters.SpamFilter.java
/** * This method checks if the hash value is still valid, i.e. if it exists at all. This * can occur in two cases: either this is a spam bot which is not adaptive, or it is * someone who has been editing one page for too long, and their session has expired. * <p>/*from w ww.ja v a 2s . c o m*/ * This method puts a redirect to the http response field to page "SessionExpired" * and logs the incident in the spam log (it may or may not be spam, but it's rather likely * that it is). * * @param context The WikiContext * @param pageContext The JSP PageContext. * @return True, if hash is okay. False, if hash is not okay, and you need to redirect. * @throws IOException If redirection fails * @since 2.6 */ public static final boolean checkHash(WikiContext context, PageContext pageContext) throws IOException { String hashName = getHashFieldName((HttpServletRequest) pageContext.getRequest()); if (pageContext.getRequest().getParameter(hashName) == null) { if (pageContext.getAttribute(hashName) == null) { Change change = getChange(context, EditorManager.getEditedText(pageContext)); log(context, REJECT, "MissingHash", change.m_change); String redirect = context.getURL(WikiContext.VIEW, "SessionExpired"); ((HttpServletResponse) pageContext.getResponse()).sendRedirect(redirect); return false; } } return true; }
From source file:net.jcreate.xkins.Context.java
/** * Constructor que recibe el pageContext y de ah saca el request, session y servletContext. * @param pctx/*from w ww. j a va2 s .c om*/ */ public Context(PageContext pctx) { this.servletRequest = pctx.getRequest(); this.servletResponse = pctx.getResponse(); }
From source file:ams.fwk.customtag.AmsDownloadTag.java
/** * context? ./* ww w .ja v a 2 s. c o m*/ * * @param page * @return String */ private String getContextPath(PageContext page) { return ((HttpServletRequest) page.getRequest()).getContextPath(); }
From source file:com.orange.wro.taglib.tag.OptionalScriptTag.java
private void writeScript(PageContext context, StringBuilder builder, String path) throws IOException { if (!StringUtils.isEmpty(path)) { HttpServletRequest req = (HttpServletRequest) context.getRequest(); String fullPath = req.getContextPath() + path; String out = String.format(WroTagLibConstants.JS_MARKUP, fullPath); builder.append(WroTagLibConstants.LESS_DEBUG_OPTIONS); builder.append(out);//from ww w . j a va2 s . co m } }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Checks that the given parameters exist. If any of them do not exist, forwards to the error page and throws * ForwardedToErrorPage./*from w w w . j av a 2 s . c o m*/ * * @param context The context of the current JSP page * @param parameters List of parameters that must exist * @throws IOFailure If the forward fails * @throws ForwardedToErrorPage If a parameter is missing */ public static void forwardOnMissingParameter(PageContext context, String... parameters) throws ForwardedToErrorPage { // Note that we may not want to be to strict here // as otherwise information could be lost. ArgumentNotValid.checkNotNull(context, "context"); ArgumentNotValid.checkNotNull(parameters, "parameters"); ServletRequest request = context.getRequest(); for (String parameter : parameters) { String value = request.getParameter(parameter); if (value == null) { forwardWithErrorMessage(context, I18N, "errormsg;missing.parameter.0", parameter); throw new ForwardedToErrorPage("Missing parameter '" + parameter + "'"); } } }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Checks that the given parameters exist and are not empty. If any of them are missing or empty, forwards to the * error page and throws ForwardedToErrorPage. A parameter with only whitespace is considered empty. * * @param context The context of the current JSP page * @param parameters List of parameters that must exist and be non-empty * @throws IOFailure If the forward fails * @throws ForwardedToErrorPage if a parameter was missing or empty *//*from w w w. j av a 2s . c om*/ public static void forwardOnEmptyParameter(PageContext context, String... parameters) { // Note that we may not want to be to strict here // as otherwise information could be lost. ArgumentNotValid.checkNotNull(context, "context"); ArgumentNotValid.checkNotNull(parameters, "parameters"); forwardOnMissingParameter(context, parameters); ServletRequest request = context.getRequest(); for (String parameter : parameters) { String value = request.getParameter(parameter); if (value.trim().length() == 0) { forwardWithErrorMessage(context, I18N, "errormsg;empty.parameter.0", parameter); throw new ForwardedToErrorPage("Empty parameter '" + parameter + "'"); } } }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Parse an optionally present long-value from a request parameter. * * @param context The context of the web request. * @param param The name of the parameter to parse. * @param defaultValue A value to return if the parameter is not present (may be null). * @return Parsed value or default value if the parameter is missing or empty. Null will only be returned if passed * as the default value./*from w ww .j a v a2 s . c o m*/ * @throws ForwardedToErrorPage if the parameter is present but not parseable as a long value. */ public static Long parseOptionalLong(PageContext context, String param, Long defaultValue) { // Note that we may not want to be to strict here // as otherwise information could be lost. ArgumentNotValid.checkNotNull(context, "context"); ArgumentNotValid.checkNotNullOrEmpty(param, "String param"); Locale loc = HTMLUtils.getLocaleObject(context); String paramValue = context.getRequest().getParameter(param); return parseLong(loc, paramValue, param, defaultValue); }
From source file:com.ideo.jso.tag.includers.RetentionIncluder.java
/** * Adds a tag into the flow to include a resource "the classic way", and suffix by a timestamp corresponding to the last modification date of the file * @param pageContext/*from w w w . j a v a 2 s . c o m*/ * @param out * @param webPath * @param tagBegin * @param tagEnd * @throws IOException */ private void includeResource(PageContext pageContext, Writer out, String webPath, String tagBegin, String tagEnd) throws IOException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); out.write(tagBegin); out.write(URLUtils.concatUrlWithSlaches(request.getContextPath(), webPath)); //TODO enable ? /*if (fileName != null && fileName.length() > 0) { long timestamp = new File(fileName).lastModified(); out.write("?"+JsoServlet.TIMESTAMP+"=" + timestamp); }*/ out.write(tagEnd); out.write("\n"); }
From source file:dk.netarkivet.common.webinterface.HTMLUtils.java
/** * Checks that the given parameter exists and is one of a set of values. If is is missing or doesn't equal one of * the given values, forwards to the error page and throws ForwardedToErrorPage. * * @param context The context of the current JSP page * @param parameter parameter that must exist * @param legalValues legal values for the parameter * @throws IOFailure If the forward fails * @throws ForwardedToErrorPage if the parameter is none of the given values */// w w w .j ava2 s . c o m public static void forwardOnIllegalParameter(PageContext context, String parameter, String... legalValues) throws ForwardedToErrorPage { // Note that we may not want to be to strict here // as otherwise information could be lost. ArgumentNotValid.checkNotNull(context, "context"); ArgumentNotValid.checkNotNull(parameter, "parameter"); ArgumentNotValid.checkNotNull(legalValues, "legalValues"); forwardOnMissingParameter(context, parameter); String value = context.getRequest().getParameter(parameter); for (String legalValue : legalValues) { if (value.equals(legalValue)) { return; } } forwardWithErrorMessage(context, I18N, "errormsg;illegal.value.0.for.parameter.1", value, parameter); throw new ForwardedToErrorPage("Illegal value '" + value + "' for parameter '" + parameter + "'"); }