Search in sources :

Example 76 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project tutorials by eugenp.

the class WelcomeServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    CookieReader cookieReader = new CookieReader(request);
    Optional<String> uiColor = cookieReader.readCookie("uiColor");
    Optional<String> userName = cookieReader.readCookie("userName");
    if (!userName.isPresent()) {
        response.sendRedirect("/login");
    } else {
        request.setAttribute("uiColor", uiColor.orElse("blue"));
        request.setAttribute("userName", userName.get());
        request.setAttribute("sessionAttribute", request.getSession().getAttribute("sampleKey"));
        RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/welcome.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 77 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project tutorials by eugenp.

the class FrontCommand method forward.

public void forward(String target) throws ServletException, IOException {
    if (intercept) {
        return;
    }
    String path = String.format("/WEB-INF/jsp/%s.jsp", target);
    RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(path);
    dispatcher.forward(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 78 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonar-java by SonarSource.

the class PerformForward method handleAsInclude.

private void handleAsInclude(String uri, ServletContext servletContext, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    RequestDispatcher rd = servletContext.getRequestDispatcher(uri);
    if (rd == null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error getting RequestDispatcher for " + uri);
        return;
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Including " + uri);
    }
    rd.include(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 79 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonar-java by SonarSource.

the class RequestProcessor method doInclude.

/**
 * <p>Do an include of specified URI using a <code>RequestDispatcher</code>.
 * This method is used by all internal method needing to do an
 * include.</p>
 *
 * @param uri      Context-relative URI to include
 * @param request  Current page request
 * @param response Current page response
 * @throws IOException      if an input/output error occurs
 * @throws ServletException if a servlet exception occurs
 * @since Struts 1.1
 */
protected void doInclude(String uri, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    RequestDispatcher rd = getServletContext().getRequestDispatcher(uri);
    if (rd == null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, getInternal().getMessage("requestDispatcher", uri));
        return;
    }
    rd.include(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 80 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project evosuite by EvoSuite.

the class EvoServletContext method createDispatcher.

// ------------ EvoSuite test methods -----------------
public void createDispatcher(String name) {
    if (name == null || name.trim().isEmpty()) {
        // do nothing
        return;
    }
    RequestDispatcher dis = new EvoRequestDispatcher(name);
    dispatchers.put(name, dis);
    TestDataJavaEE.getInstance().accessedDispatcher(name);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)354 ServletException (javax.servlet.ServletException)98 HttpSession (javax.servlet.http.HttpSession)97 IOException (java.io.IOException)74 HttpServletRequest (javax.servlet.http.HttpServletRequest)56 HttpServletResponse (javax.servlet.http.HttpServletResponse)44 SQLException (java.sql.SQLException)31 User (com.zyf.bean.User)28 ServletContext (javax.servlet.ServletContext)26 Properties (java.util.Properties)14 Test (org.junit.Test)14 RelatorioDAO (br.senac.tads3.pi03b.gruposete.dao.RelatorioDAO)13 RelatorioMudancas (br.senac.tads3.pi03b.gruposete.models.RelatorioMudancas)12 PrintWriter (java.io.PrintWriter)12 RequestDispatcherOptions (org.apache.sling.api.request.RequestDispatcherOptions)11 Resource (org.apache.sling.api.resource.Resource)11 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 GenericValue (org.apache.ofbiz.entity.GenericValue)9 WebUser (org.compiere.util.WebUser)9