Java Code Examples for javax.servlet.ServletRequest#getParameter()

The following examples show how to use javax.servlet.ServletRequest#getParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListTagHelper.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * returns the value that the list is being filtered upon.  (null if not being filtered)
 * @param request the request to look in
 * @param uniqueName the unique (hashed) name for the list
 * @return the filter value
 */
public static String getFilterValue(ServletRequest request, String uniqueName) {

    String newValue = request.getParameter(
            ListTagUtil.makeFilterValueByLabel(uniqueName));
    String oldValue = request.getParameter(
            ListTagUtil.makeOldFilterValueByLabel(uniqueName));

    String clicked =
        request.getParameter(ListTagUtil.makeFilterNameByLabel(uniqueName));

    if (clicked == null) {
        if (oldValue  != null && !oldValue.equals("null")) {
            return StringEscapeUtils.escapeHtml(oldValue);
        }
        return "";
    }
    return StringEscapeUtils.escapeHtml(newValue);
}
 
Example 2
Source File: SystemMessagePublishServiceImpl.java    From bamboobsc with Apache License 2.0 6 votes vote down vote up
@Override
public WebMessagePublishBaseObj execute(SysMsgNoticeConfigVO config, ServletRequest request) throws ServiceException, Exception {
	this.request = request;
	WebMessagePublishBaseObj publishObj = new WebMessagePublishBaseObj();
	String account = request.getParameter("account");
	String refreshUUID = StringUtils.defaultString(request.getParameter("refreshUUID")).trim();
	String sessionId = ((HttpServletRequest)request).getSession().getId();
	AccountVO accountObj = (AccountVO) UserAccountHttpSessionSupport.get( (HttpServletRequest)request );
	if (StringUtils.isBlank(this.getId()) || StringUtils.isBlank(account) || accountObj==null ) { // no login
		return publishObj;
	}
	if (!account.equals(accountObj.getAccount())) { // not same account request
		return publishObj;
	}
	List<TbSysMsgNotice> globalSysMsgNoticeList = this.loadGlobalSysMsgNoticeData(config.getMsgId(), "*");
	List<TbSysMsgNotice> accountSysMsgNoticeList = this.loadAccountSysMsgNoticeData(config.getMsgId(), account);
	String globalMsg = this.process(sessionId, refreshUUID, globalSysMsgNoticeList);
	String personalMsg = this.process(sessionId, refreshUUID, accountSysMsgNoticeList);
	publishObj.setIsAuthorize(YesNo.YES);
	publishObj.setLogin(YesNo.YES);
	publishObj.setSuccess(YesNo.YES);
	publishObj.setMessage(globalMsg+personalMsg);
	return publishObj;
}
 
Example 3
Source File: RhnUnpagedListAction.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets up the ListControl filter data
 * @param lc ListControl to use
 * @param request ServletRequest
 * @param viewer user requesting the page
 */
public void filterList(ListControl lc, ServletRequest request, User viewer) {
    /*
     * Make sure we have a user. If not, something bad happened and we should
     * just bail out with an exception. Since this is probably the result of
     * a bad uid param, throw a BadParameterException.
     */
    if (viewer == null) {
        throw new BadParameterException("Null viewer");
    }

    String filterData = request.getParameter(RequestContext.FILTER_STRING);
    request.setAttribute("isFiltered",
        Boolean.valueOf(!StringUtils.isEmpty(filterData)));
    if (!StringUtils.isBlank(filterData)) {
        HttpServletRequest req = (HttpServletRequest) request;
        createSuccessMessage(req, "filter.clearfilter", req.getRequestURI());
    }

    lc.setFilterData(filterData);
}
 
Example 4
Source File: ServletRequestUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get a Float parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current HTTP request
 * @param name the name of the parameter
 * @return the Float value, or {@code null} if not present
 * @throws ServletRequestBindingException a subclass of ServletException,
 * so it doesn't need to be caught
 */
@Nullable
public static Float getFloatParameter(ServletRequest request, String name)
		throws ServletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredFloatParameter(request, name);
}
 
Example 5
Source File: BIRTLanguageFilter.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
	String preferredLanguage = request.getParameter("language");
	if (StringUtils.isNotEmpty(preferredLanguage)) {
		filterChain.doFilter(new ForceLocaleRequestWrapper((HttpServletRequest) request, preferredLanguage), response);
	} else {
		filterChain.doFilter(request, response);
	}
}
 
Example 6
Source File: ServletRequestUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get a boolean parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value as default to enable checks of whether it was supplied.
 * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true;
 * treats every other non-empty value as false (i.e. parses leniently).
 * @param request current HTTP request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static boolean getBooleanParameter(ServletRequest request, String name, boolean defaultVal) {
	if (request.getParameter(name) == null) {
		return defaultVal;
	}
	try {
		return getRequiredBooleanParameter(request, name);
	}
	catch (ServletRequestBindingException ex) {
		return defaultVal;
	}
}
 
Example 7
Source File: WebUtils2.java    From super-cloudops with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method that returns a request parameter value, first running
 * it through {@link StringUtils#clean(String)}.
 *
 * @param request
 *            the servlet request.
 * @param paramName
 *            the parameter name.
 * @return the clean param value, or null if the param does not exist or is
 *         empty.
 */
public static String getRequestParam(ServletRequest request, String paramName, boolean required) {
	String paramValue = request.getParameter(paramName);
	String cleanedValue = paramValue;
	if (paramValue != null) {
		cleanedValue = paramValue.trim();
		if (cleanedValue.equals(EMPTY)) {
			cleanedValue = null;
		}
	}
	if (required) {
		hasTextOf(cleanedValue, paramName);
	}
	return cleanedValue;
}
 
Example 8
Source File: TestHttpServer.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response,
    FilterChain filterChain) throws IOException, ServletException {
  final String userName = request.getParameter("user.name");
  ServletRequest requestModified =
    new HttpServletRequestWrapper((HttpServletRequest) request) {
    @Override
    public String getRemoteUser() {
      return userName;
    }
  };
  filterChain.doFilter(requestModified, response);
}
 
Example 9
Source File: ServletRequestUtils.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Get a String parameter, or {@code null} if not present.
 * @param request current HTTP request
 * @param name the name of the parameter
 * @return the String value, or {@code null} if not present
 * @throws ServletRequestBindingException a subclass of ServletException,
 * so it doesn't need to be caught
 */
@Nullable
public static String getStringParameter(ServletRequest request, String name)
		throws ServletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredStringParameter(request, name);
}
 
Example 10
Source File: ServletRequestUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get an Integer parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current HTTP request
 * @param name the name of the parameter
 * @return the Integer value, or {@code null} if not present
 * @throws ServletRequestBindingException a subclass of ServletException,
 * so it doesn't need to be caught
 */
@Nullable
public static Integer getIntParameter(ServletRequest request, String name)
		throws ServletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredIntParameter(request, name);
}
 
Example 11
Source File: FederationAuthenticator.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
private String getState(ServletRequest request) {
    if (request.getParameter(FederationConstants.PARAM_CONTEXT) != null) {
        return request.getParameter(FederationConstants.PARAM_CONTEXT);
    } else if (request.getParameter(SAMLSSOConstants.RELAY_STATE) != null) {
        return request.getParameter(SAMLSSOConstants.RELAY_STATE);
    }

    return null;
}
 
Example 12
Source File: EmptyParamFilter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse,
    FilterChain filterChain) throws IOException, ServletException {
    String inputString = servletRequest.getParameter("input");

    if (inputString != null && inputString.matches("[A-Za-z0-9]+")) {
        filterChain.doFilter(servletRequest, servletResponse);
    } else {
        servletResponse.getWriter().println("Missing input parameter");
    }
}
 
Example 13
Source File: FederationSignOutCleanupFilter.java    From cxf-fediz with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {

    String wa = request.getParameter(FederationConstants.PARAM_ACTION);
    if (FederationConstants.ACTION_SIGNOUT_CLEANUP.equals(wa)) {
        if (request instanceof HttpServletRequest) {
            ((HttpServletRequest)request).getSession().invalidate();
        }

        final ServletOutputStream responseOutputStream = response.getOutputStream();
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("logout.jpg");
        if (inputStream == null) {
            LOG.warn("Could not write logout.jpg");
            return;
        }
        int read = 0;
        byte[] buf = new byte[1024];
        while ((read = inputStream.read(buf)) != -1) {
            responseOutputStream.write(buf, 0, read);
        }
        inputStream.close();
        responseOutputStream.flush();
    } else {
        chain.doFilter(request, response);
    }
}
 
Example 14
Source File: ServletRequestUtils.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Get a Long parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a number.
 * @param request current HTTP request
 * @param name the name of the parameter
 * @return the Long value, or {@code null} if not present
 * @throws ServletRequestBindingException a subclass of ServletException,
 * so it doesn't need to be caught
 */
@Nullable
public static Long getLongParameter(ServletRequest request, String name)
		throws ServletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return getRequiredLongParameter(request, name);
}
 
Example 15
Source File: PublicProfile.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static UserProfile evaluatePublicCase(ServletRequest request, HttpSession session, SessionContainer permanentSession) {

		UserProfile toReturn = null;

		if (((HttpServletRequest) request).getServletPath().contains(PUBLIC_PATTERN_MATCH)) {

			String organization = null;
			if (request.getParameter("ORGANIZATION") != null) {
				organization = request.getParameter("ORGANIZATION").toString();
			}
			if (organization == null) {
				throw new SpagoBIRuntimeException("Public request must specify ORGANIZATION");
			}

			String userId = PUBLIC_USER_PREFIX + organization;
			logger.debug("Public User Id is " + userId);

			SpagoBIUserProfile spagoBIProfile = createPublicUserProfile(userId);

			toReturn = new UserProfile(spagoBIProfile);

			if (permanentSession != null)
				permanentSession.setAttribute(IEngUserProfile.ENG_USER_PROFILE, toReturn);
			if (session != null)
				session.setAttribute(IEngUserProfile.ENG_USER_PROFILE, toReturn);
		}
		return toReturn;
	}
 
Example 16
Source File: RegServlet.java    From onlineTest with Apache License 2.0 5 votes vote down vote up
@Override
public void service(ServletRequest request, ServletResponse response)
		throws ServletException, IOException {
	    
	request.setCharacterEncoding("utf-8");
	response.setContentType("text/html;charset=utf-8");
	String loginname = request.getParameter("loginname");
	String password = request.getParameter("password");
	String email = request.getParameter("email");
	String phone = request.getParameter("phone");
	String sex = request.getParameter("sex");
	String birth = request.getParameter("birth");
	String uname = request.getParameter("uname");
	
	User user = new User(0, loginname, password, email, phone, sex, birth, uname, "0");
	UserDAO userDAO = new UserDAO();
	PrintWriter out = response.getWriter();
	out.println("<!DOCTYPE html>");
	out.println("<html>");
	out.println("	<head>");
	out.println("	</head>");
	out.println("	<body>");
	if(userDAO.add(user)){
		out.println("	恭喜,注册成功!<a href=\"/login.html\">进入登录页面</a>");
	}else{
		out.println("	抱歉,注册失败!<a href=\"/reg.html\">回到首页</a>");
	}
	out.println("	</body>");
	out.println("</html>");
	out.flush();
	out.close();
}
 
Example 17
Source File: SakaiIFrame.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
	response.setContentType("text/html");

	log.debug("==== doView called ====");

	// Grab that underlying request to get a GET parameter
	ServletRequest req = (ServletRequest) ThreadLocalManager.get(CURRENT_HTTP_REQUEST);
	String popupDone = req.getParameter("sakai.popup");

	PrintWriter out = response.getWriter();
	Placement placement = ToolManager.getCurrentPlacement();
	response.setTitle(placement.getTitle());
	String source = placement.getPlacementConfig().getProperty(SOURCE);
	if ( source == null ) source = "";
	String height = placement.getPlacementConfig().getProperty(HEIGHT);
	if ( height == null ) height = "1200px";
	boolean maximize = "true".equals(placement.getPlacementConfig().getProperty(MAXIMIZE));

	boolean popup = false; // Comes from content item
	boolean oldPopup = "true".equals(placement.getPlacementConfig().getProperty(POPUP));

	// Retrieve the corresponding content item and tool to check the launch
	Map<String, Object> content = null;
	Map<String, Object> tool = null;
	Long contentId = getContentIdFromSource(source);
	if ( contentId == null ) {
		out.println(rb.getString("get.info.notconfig"));
		log.warn("Cannot find content id placement={} source={}", placement.getId(), source);
		return;
	}
	try {
		content = m_ltiService.getContent(contentId, placement.getContext());
		// SAK-32665 - We get null when an LTI tool is added to a template
		// like !user because the content item points at !user and not the
		// current site.
		if ( content == null ) {
			content = patchContentItem(contentId, placement);
			source = placement.getPlacementConfig().getProperty(SOURCE);
			contentId = getContentIdFromSource(source);
		}

		// If content is still null after patching, let the NPE happen
		Long tool_id = getLongNull(content.get("tool_id"));
		// If we are supposed to popup (per the content), do so and optionally
		// copy the calue into the placement to communicate with the portal
		if (tool_id != null) {
			tool = m_ltiService.getTool(tool_id, placement.getContext());
			m_ltiService.filterContent(content, tool);
		}
		Object popupValue = content.get("newpage");
		popup = getLongNull(popupValue) == 1;
		if ( oldPopup != popup ) {
			placement.getPlacementConfig().setProperty(POPUP, popup ? "true" : "false");
			placement.save();
		}
		String launch = (String) content.get("launch");
		// Force http:// to pop-up if we are https://
		String serverUrl = ServerConfigurationService.getServerUrl();
		if ( request.isSecure() || ( serverUrl != null && serverUrl.startsWith("https://") ) ) {
			if ( launch != null && launch.startsWith("http://") ) popup = true;
		}
	} catch (Exception e) {
		out.println(rb.getString("get.info.notconfig"));
		log.error(e.getMessage(), e);
		return;
	}

	if ( source != null && source.trim().length() > 0 ) {

		Context context = new VelocityContext();
		context.put("tlang", rb);
		context.put("validator", formattedText);
		context.put("source",source);
		context.put("height",height);
		context.put("browser-feature-allow", String.join(";", ServerConfigurationService.getStrings("browser.feature.allow")));
		sendAlert(request,context);
		context.put("popupdone", Boolean.valueOf(popupDone != null));
		context.put("popup", Boolean.valueOf(popup));
		context.put("maximize", Boolean.valueOf(maximize));

		vHelper.doTemplate(vengine, "/vm/main.vm", context, out);
	} else {
		out.println(rb.getString("get.info.notconfig"));
	}
}
 
Example 18
Source File: ServletRequestUtils.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Get a Boolean parameter, or {@code null} if not present.
 * Throws an exception if it the parameter value isn't a boolean.
 * <p>Accepts "true", "on", "yes" (any case) and "1" as values for true;
 * treats every other non-empty value as false (i.e. parses leniently).
 * @param request current HTTP request
 * @param name the name of the parameter
 * @return the Boolean value, or {@code null} if not present
 * @throws ServletRequestBindingException a subclass of ServletException,
 * so it doesn't need to be caught
 */
public static Boolean getBooleanParameter(ServletRequest request, String name)
		throws ServletRequestBindingException {

	if (request.getParameter(name) == null) {
		return null;
	}
	return (getRequiredBooleanParameter(request, name));
}
 
Example 19
Source File: AlphaBarHelper.java    From uyuni with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns the alpha value..
 * @param listName the name of this list, ncessary for unique identification
 * @param req the servlet request.
 * @return the alpha value
 */
public String getAlphaValue(String listName, ServletRequest req) {
    return req.getParameter(makeAlphaKey(listName));
}
 
Example 20
Source File: ServletRequestUtils.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get a String parameter, with a fallback value. Never throws an exception.
 * Can pass a distinguished value to default to enable checks of whether it was supplied.
 * @param request current HTTP request
 * @param name the name of the parameter
 * @param defaultVal the default value to use as fallback
 */
public static String getStringParameter(ServletRequest request, String name, String defaultVal) {
	String val = request.getParameter(name);
	return (val != null ? val : defaultVal);
}