Search in sources :

Example 11 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonarqube by SonarSource.

the class ExceptionHandler method handleCommittedResponse.

/**
     * <p>Attempt to give good information when the response has already been
     * committed when the exception was thrown. This happens often when Tiles
     * is used. Base implementation will see if the INCLUDE_PATH property has
     * been set, or if not, it will attempt to use the same path to which
     * control would have been forwarded.</p>
     *
     * @param ex            The exception to handle
     * @param config        The ExceptionConfig we are processing
     * @param mapping       The ActionMapping we are processing
     * @param formInstance  The ActionForm we are processing
     * @param request       The servlet request we are processing
     * @param response      The servlet response we are creating
     * @param actionForward The ActionForward we are processing
     * @since Struts 1.3
     */
protected void handleCommittedResponse(Exception ex, ExceptionConfig config, ActionMapping mapping, ActionForm formInstance, HttpServletRequest request, HttpServletResponse response, ActionForward actionForward) {
    String includePath = determineIncludePath(config, actionForward);
    if (includePath != null) {
        if (includePath.startsWith("/")) {
            LOG.debug("response committed, " + "but attempt to include results " + "of actionForward path");
            RequestDispatcher requestDispatcher = request.getRequestDispatcher(includePath);
            try {
                requestDispatcher.include(request, response);
                return;
            } catch (IOException e) {
                LOG.error("IOException when trying to include " + "the error page path " + includePath, e);
            } catch (ServletException e) {
                LOG.error("ServletException when trying to include " + "the error page path " + includePath, e);
            }
        } else {
            LOG.warn("Suspicious includePath doesn't seem likely to work, " + "so skipping it: " + includePath + "; expected path to start with '/'");
        }
    }
    LOG.debug("Include not available or failed; " + "try writing to the response directly.");
    try {
        response.getWriter().println("Unexpected error: " + ex);
        response.getWriter().println("<!-- ");
        ex.printStackTrace(response.getWriter());
        response.getWriter().println("-->");
    } catch (IOException e) {
        LOG.error("Error giving minimal information about exception", e);
        LOG.error("Original exception: ", ex);
    }
}
Also used : ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 12 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonarqube by SonarSource.

the class RequestProcessor method doForward.

/**
     * <p>Do a forward to specified URI using a <code>RequestDispatcher</code>.
     * This method is used by all internal method needing to do a
     * forward.</p>
     *
     * @param uri      Context-relative URI to forward to
     * @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 doForward(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.forward(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 13 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonarqube by SonarSource.

the class PerformInclude method perform.

// ------------------------------------------------------- Protected Methods
/**
     * <p>Perform the appropriate processing on the specified include
     * uri.</p>
     *
     * @param context The context for this request
     * @param uri     The uri to be included
     */
protected void perform(ActionContext context, String uri) throws Exception {
    ServletActionContext swcontext = (ServletActionContext) context;
    HttpServletRequest request = swcontext.getRequest();
    RequestDispatcher rd = swcontext.getContext().getRequestDispatcher(uri);
    rd.forward(request, swcontext.getResponse());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 14 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project sonarqube 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 15 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project javaee7-samples by javaee-samples.

the class ClientServlet method processRequest.

/**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>CDI Scopes</title>");
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>CDI Scopes</h1>");
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/ServerServlet");
        out.println("<h2>First request</h2>");
        dispatcher.include(request, response);
        out.println("<h2>Second request</h2>");
        dispatcher.include(request, response);
        out.println("</body>");
        out.println("</html>");
    }
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher) PrintWriter(java.io.PrintWriter)

Aggregations

RequestDispatcher (javax.servlet.RequestDispatcher)203 ServletException (javax.servlet.ServletException)63 HttpSession (javax.servlet.http.HttpSession)58 IOException (java.io.IOException)41 SQLException (java.sql.SQLException)31 HttpServletRequest (javax.servlet.http.HttpServletRequest)30 HttpServletResponse (javax.servlet.http.HttpServletResponse)26 Properties (java.util.Properties)14 ServletContext (javax.servlet.ServletContext)12 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 WebUser (org.compiere.util.WebUser)9 ClienteDAO (br.senac.tads3.pi03b.gruposete.dao.ClienteDAO)8 PrintWriter (java.io.PrintWriter)8 ServletResponse (javax.servlet.ServletResponse)8 Cliente (br.senac.tads3.pi03b.gruposete.models.Cliente)7 ServletRequest (javax.servlet.ServletRequest)7 User (org.opennms.netmgt.config.users.User)7 HotelDAO (br.senac.tads3.pi03b.gruposete.dao.HotelDAO)6 VooDAO (br.senac.tads3.pi03b.gruposete.dao.VooDAO)6