Tabnine Logo
javax.servlet
Code IndexAdd Tabnine to your IDE (free)

How to use javax.servlet

Best Java code snippets using javax.servlet (Showing top 20 results out of 47,529)

origin: stackoverflow.com

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
  if (((HttpServletRequest) request).getSession().getAttribute("user") == null) {
    ((HttpServletResponse) response).sendRedirect("login"); // Not logged in, redirect to login page.
  } else {
    chain.doFilter(request, response); // Logged in, just continue request.
  }
}
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: spring-projects/spring-framework

/**
 * 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);
}
origin: spring-projects/spring-framework

  @Override
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    request.setAttribute(FROM_REQUEST_FILTER, FROM_REQUEST_FILTER);
    chain.doFilter(request, response);
  }
}
origin: spring-projects/spring-framework

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  this.invoked = true;
  if (this.servlet != null) {
    this.servlet.service(request, response);
  }
  else {
    chain.doFilter(request, response);
  }
}
origin: spring-projects/spring-framework

@Override
protected void initServletContext(ServletContext servletContext) {
  if (this.serverContainer == null) {
    this.serverContainer =
        (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer");
  }
}
origin: spring-projects/spring-framework

/**
 * Expose the specified request attribute if not already present.
 * @param request current servlet request
 * @param name the name of the attribute
 * @param value the suggested value of the attribute
 */
private static void exposeRequestAttributeIfNotPresent(ServletRequest request, String name, Object value) {
  if (request.getAttribute(name) == null) {
    request.setAttribute(name, value);
  }
}
origin: spring-projects/spring-framework

/**
 * Determine whether the given request is an include request,
 * that is, not a top-level HTTP request coming in from the outside.
 * <p>Checks the presence of the "javax.servlet.include.request_uri"
 * request attribute. Could check any request attribute that is only
 * present in an include request.
 * @param request current servlet request
 * @return whether the given request is an include request
 */
public static boolean isIncludeRequest(ServletRequest request) {
  return (request.getAttribute(INCLUDE_REQUEST_URI_ATTRIBUTE) != null);
}
origin: spring-projects/spring-framework

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
    throws IOException, ServletException {
  request.setAttribute("called", Boolean.TRUE);
}
origin: spring-projects/spring-framework

@Override
public <T extends EventListener> void addListener(T t) {
  if (t instanceof ServletContextListener) {
    ((ServletContextListener) t).contextInitialized(new ServletContextEvent(this));
  }
}
origin: spring-projects/spring-framework

/**
 * Initialize all the filters, calling each one's init method in turn in the order supplied.
 * @see Filter#init(FilterConfig)
 */
@Override
public void init(FilterConfig config) throws ServletException {
  for (Filter filter : this.filters) {
    filter.init(config);
  }
}
origin: spring-projects/spring-framework

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  this.delegateServlet.service(request, response);
}
origin: spring-projects/spring-framework

@Override
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
  if (bean instanceof Servlet) {
    ((Servlet) bean).destroy();
  }
}
origin: spring-projects/spring-framework

private static Object getNativeRequest(ServletRequest request) {
  while (request instanceof ServletRequestWrapper) {
    request = ((ServletRequestWrapper) request).getRequest();
  }
  return request;
}
origin: spring-projects/spring-framework

  @Override
  public void setWriteListener(WriteListener writeListener) {
    this.os.setWriteListener(writeListener);
  }
}
origin: spring-projects/spring-framework

  @Override
  public void setReadListener(ReadListener readListener) {
    this.is.setReadListener(readListener);
  }
}
origin: spring-projects/spring-framework

  @Override
  public long getTimeout() {
    return this.delegate.getTimeout();
  }
}
origin: spring-projects/spring-framework

  @Override
  protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
      FilterChain filterChain) throws ServletException, IOException {
    filterChain.doFilter(request, response);
  }
}
origin: spring-projects/spring-framework

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException {
  this.delegateServlet.service(request, response);
}
origin: spring-projects/spring-framework

/**
 * Destroy the wrapped Servlet instance.
 * @see javax.servlet.Servlet#destroy()
 */
@Override
public void destroy() {
  if (this.servletInstance != null) {
    this.servletInstance.destroy();
  }
}
javax.servlet

Most used classes

  • HttpServletRequest
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • HttpServletResponse
    Extends the ServletResponse interface to provide HTTP-specific functionality in sending a response.
  • ServletContext
    Defines a set of methods that a servlet uses to communicate with its servlet container, for example,
  • FilterChain
    A FilterChain is an object provided by the servlet container to the developer giving a view into the
  • HttpSession
    Provides a way to identify a user across more than one page request or visit to a Web site and to st
  • ServletOutputStream,
  • ServletRequest,
  • Cookie,
  • ServletConfig,
  • FilterConfig,
  • ServletContextEvent,
  • HttpServlet,
  • RequestDispatcher,
  • ServletResponse,
  • HttpServletRequestWrapper,
  • HttpServletResponseWrapper,
  • PageContext,
  • HttpSessionEvent,
  • JspWriter
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