Tabnine Logo
HttpServletRequest.setAttribute
Code IndexAdd Tabnine to your IDE (free)

How to use
setAttribute
method
in
javax.servlet.http.HttpServletRequest

Best Java code snippets using javax.servlet.http.HttpServletRequest.setAttribute (Showing top 20 results out of 9,621)

Refine searchRefine arrow

  • ActionMapping.findForward
  • HttpServletRequest.getParameter
  • HttpServletRequest.getAttribute
  • HttpServletRequest.getRequestDispatcher
  • RequestDispatcher.forward
origin: stackoverflow.com

 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  try {
    List<Product> products = productService.list(); // Obtain all products.
    request.setAttribute("products", products); // Store products in request scope.
    request.getRequestDispatcher("/WEB-INF/products.jsp").forward(request, response); // Forward to JSP page to display them in a HTML table.
  } catch (SQLException e) {
    throw new ServletException("Retrieving products failed!", e);
  }
}
origin: stackoverflow.com

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String username = request.getParameter("username");
  String password = request.getParameter("password");
  User user = userService.find(username, password);

  if (user != null) {
    request.getSession().setAttribute("user", user); // Login user.
    response.sendRedirect("home"); // Redirect to home page.
  } else {
    request.setAttribute("message", "Unknown username/password. Please retry."); // Store error message in request scope.
    request.getRequestDispatcher("/WEB-INF/login.jsp").forward(request, response); // Forward to JSP page to redisplay login form with error.
  }
}
origin: stackoverflow.com

 public class LoginAction implements Action {

  public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    User user = userDAO.find(username, password);

    if (user != null) {
      request.getSession().setAttribute("user", user); // Login user.
      return "home"; // Redirect to home page.
    }
    else {
      request.setAttribute("error", "Unknown username/password. Please retry."); // Store error message in request scope.
      return "login"; // Go back to redisplay login form with error.
    }
  }

}
origin: FenixEdu/fenixedu-academic

public ActionForward enrolInCycleCourseGroupInvalid(ActionMapping mapping, ActionForm form, HttpServletRequest request,
    HttpServletResponse response) {
  request.setAttribute("cycleEnrolmentBean", getCycleEnrolmentBeanFromViewState());
  request.setAttribute("withRules", request.getParameter("withRules"));
  return mapping.findForward("chooseCycleCourseGroupToEnrol");
}
origin: stackoverflow.com

 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  String  pro_code  = request.getParameter("pro_code");
  String  name  = request.getParameter("name");
  String  price  = request.getParameter("price");

  // do something usefull with the parameters here

  // expose the results to the jsp like so:
  request.setAttribute("pro_code", pro_code);  
  request.setAttribute("name", name);  
  request.setAttribute("price",price); 
  RequestDispatcher rd = request.getRequestDispatcher("/studentSearch.jsp");
  rd.forward(request, response);
}
origin: spring-projects/spring-framework

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws ServletException {
  if (request.getAttribute("test2") != null) {
    throw new ServletException("Wrong interceptor order");
  }
  request.setAttribute("test1", "test1");
  request.setAttribute("test1x", "test1x");
  request.setAttribute("test1y", "test1y");
  return true;
}
origin: spring-projects/spring-framework

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
    throws ServletException {
  if (request.getAttribute("test1x") == null) {
    throw new ServletException("Wrong interceptor order");
  }
  if (request.getParameter("abort") != null) {
    return false;
  }
  request.setAttribute("test2", "test2");
  request.setAttribute("test2x", "test2x");
  request.setAttribute("test2y", "test2y");
  return true;
}
origin: ocpsoft/prettytime

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  request.setAttribute("myDate", new Date());
  request.getRequestDispatcher("/WEB-INF/index.jsp").forward(request, response);
}
origin: stackoverflow.com

 public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException {

  // fetch the username that was sent in the request
  String username = request.getParameter("username");

  // TODO: verify if the username is taken in the database

  // based on the results set the value
  request.setAttribute("isUsernameTaken", "true");

  RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/register.jsp");

  dispatcher.forward(request, response);      
}
origin: spring-projects/spring-framework

@Test
public void includeOnAttribute() throws Exception {
  given(request.getAttribute(View.PATH_VARIABLES)).willReturn(null);
  given(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).willReturn("somepath");
  given(request.getRequestDispatcher(url)).willReturn(new MockRequestDispatcher(url));
  view.setUrl(url);
  // Can now try multiple tests
  view.render(model, request, response);
  assertEquals(url, response.getIncludedUrl());
  model.forEach((key, value) -> verify(request).setAttribute(key, value));
}
origin: cloudfoundry/uaa

protected void validateParamsAndContinue(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
  for (Map.Entry<String, String[]> entry : request.getParameterMap().entrySet()) {
    if (entry.getValue() != null && entry.getValue().length >0) {
      for (String s : entry.getValue()) {
        if (hasText(s) && s.contains(NULL_STRING)) {
          response.setStatus(400);
          request.setAttribute("error_message_code", "request.invalid_parameter");
          request.getRequestDispatcher("/error").forward(request,response);
          return;
        }
      }
    }
  }
  chain.doFilter(request, response);
}
origin: spring-projects/spring-framework

  request.removeAttribute(attrName);
else if (attrValue != request.getAttribute(attrName)) {
  request.setAttribute(attrName, attrValue);
origin: com.google.inject.extensions/guice-servlet

final HttpServletResponse mockResponse = createMock(HttpServletResponse.class);
expect(requestMock.getAttribute(A_KEY)).andReturn(A_VALUE);
requestMock.setAttribute(REQUEST_DISPATCHER_REQUEST, true);
requestMock.removeAttribute(REQUEST_DISPATCHER_REQUEST);
dispatcher.forward(requestMock, mockResponse);
origin: stackoverflow.com

 public class AccountServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

  List<Account> accounts = getAccountListFromSomewhere();

  String url="..."; //relative url for display jsp page
  ServletContext sc = getServletContext();
  RequestDispatcher rd = sc.getRequestDispatcher(url);

  request.setAttribute("accountList", accounts );
  rd.forward(request, response);
 }
}
origin: BroadleafCommerce/BroadleafCommerce

request.setAttribute("typedEntitySection", typedEntitySection);
wrapper.getRequestDispatcher(wrapper.getServletPath()).forward(wrapper, response);
return true;
origin: FenixEdu/fenixedu-academic

public ActionForward invalid(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request,
    HttpServletResponse response) {
  final Student student = FenixFramework.getDomainObject(request.getParameter("studentOID"));
  request.setAttribute("student", student);
  request.setAttribute("schemaName", request.getParameter("schemaName"));
  request.setAttribute("manageStatuteBean", getRenderedObject());
  return mapping.findForward("manageStatutes");
}
origin: org.entando.entando/entando-core-engine

private void sendToAuthorizePage(HttpServletRequest request, 
    HttpServletResponse response, OAuthAccessor accessor) throws IOException, ServletException {
  String callback = request.getParameter("oauth_callback");
  if (callback == null || callback.length() <= 0) {
    callback = "none";
  }
  String consumer_description = (String)accessor.consumer.getProperty("description");
  request.setAttribute("oauthParam_CONSUMER_DESCRIPTION", consumer_description);
  request.setAttribute("oauthParam_CALLBACK_URL", callback);
  request.setAttribute("oauthParam_REQUEST_TOKEN", accessor.requestToken);
  request.getRequestDispatcher("/WEB-INF/aps/jsp/oauth/authorize.jsp").forward(request, response);
}

origin: stackoverflow.com

 @WebServlet("/product")
public class ProductServlet extends HttpServlet {

  @EJB
  private ProductService productService;

  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Product product = productService.find(request.getParameter("id"));
    request.setAttribute("product", product); // Will be available as ${product} in JSP
    request.getRequestDispatcher("/WEB-INF/product.jsp").forward(request, response);
  }

}
origin: spring-projects/spring-security-oauth

protected String extractToken(HttpServletRequest request) {
  // first check the header...
  String token = extractHeaderToken(request);
  // bearer type allows a request parameter as well
  if (token == null) {
    logger.debug("Token not found in headers. Trying request parameters.");
    token = request.getParameter(OAuth2AccessToken.ACCESS_TOKEN);
    if (token == null) {
      logger.debug("Token not found in request parameters.  Not an OAuth2 request.");
    }
    else {
      request.setAttribute(OAuth2AuthenticationDetails.ACCESS_TOKEN_TYPE, OAuth2AccessToken.BEARER_TYPE);
    }
  }
  return token;
}
origin: spring-projects/spring-framework

@Override
public String resolveThemeName(HttpServletRequest request) {
  // Check request for preparsed or preset theme.
  String themeName = (String) request.getAttribute(THEME_REQUEST_ATTRIBUTE_NAME);
  if (themeName != null) {
    return themeName;
  }
  // Retrieve cookie value from request.
  String cookieName = getCookieName();
  if (cookieName != null) {
    Cookie cookie = WebUtils.getCookie(request, cookieName);
    if (cookie != null) {
      String value = cookie.getValue();
      if (StringUtils.hasText(value)) {
        themeName = value;
      }
    }
  }
  // Fall back to default theme.
  if (themeName == null) {
    themeName = getDefaultThemeName();
  }
  request.setAttribute(THEME_REQUEST_ATTRIBUTE_NAME, themeName);
  return themeName;
}
javax.servlet.httpHttpServletRequestsetAttribute

Popular methods of HttpServletRequest

  • getHeader
    Returns the value of the specified request header as a String. If the request did not include a head
  • getParameter
  • getRequestURI
    Returns the part of this request's URL from the protocol name up to the query string in the first li
  • getSession
    Returns the current HttpSession associated with this request or, if there is no current session and
  • getMethod
    Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT
  • getAttribute
  • getContextPath
    Returns the portion of the request URI that indicates the context of the request. The context path a
  • getQueryString
    Returns the query string that is contained in the request URL after the path. This method returns nu
  • getPathInfo
    Returns any extra path information associated with the URL the client sent when it made this request
  • getRequestURL
    Reconstructs the URL the client used to make the request. The returned URL contains a protocol, serv
  • getRemoteAddr
  • getServletPath
    Returns the part of this request's URL that calls the servlet. This path starts with a "/" character
  • getRemoteAddr,
  • getServletPath,
  • getInputStream,
  • getParameterMap,
  • getCookies,
  • getServerName,
  • getHeaderNames,
  • getScheme,
  • getServerPort

Popular in Java

  • Making http requests using okhttp
  • notifyDataSetChanged (ArrayAdapter)
  • getSharedPreferences (Context)
  • getResourceAsStream (ClassLoader)
  • Runnable (java.lang)
    Represents a command that can be executed. Often used to run code in a different Thread.
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now