Search in sources :

Example 66 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project knox by apache.

the class GatewayForwardingServletTest method testRedirectDefaults.

@Test
public void testRedirectDefaults() throws ServletException, IOException {
    IMocksControl mockControl = EasyMock.createControl();
    ServletConfig config = (ServletConfig) mockControl.createMock(ServletConfig.class);
    ServletContext context = (ServletContext) mockControl.createMock(ServletContext.class);
    HttpServletRequest request = (HttpServletRequest) mockControl.createMock(HttpServletRequest.class);
    HttpServletResponse response = (HttpServletResponse) mockControl.createMock(HttpServletResponse.class);
    RequestDispatcher dispatcher = (RequestDispatcher) mockControl.createMock(RequestDispatcher.class);
    // setup expectations
    EasyMock.expect(config.getServletName()).andStubReturn("default");
    EasyMock.expect(config.getServletContext()).andStubReturn(context);
    EasyMock.expect(config.getInitParameter("redirectTo")).andReturn("/gateway/sandbox");
    EasyMock.expect(request.getMethod()).andReturn("GET").anyTimes();
    EasyMock.expect(request.getPathInfo()).andReturn("/webhdfs/v1/tmp").anyTimes();
    EasyMock.expect(request.getQueryString()).andReturn("op=LISTSTATUS");
    EasyMock.expect(response.getStatus()).andReturn(200).anyTimes();
    EasyMock.expect(context.getContext("/gateway/sandbox")).andReturn(context);
    EasyMock.expect(context.getRequestDispatcher("/webhdfs/v1/tmp?op=LISTSTATUS")).andReturn(dispatcher);
    dispatcher.forward(request, response);
    EasyMock.expectLastCall().once();
    // logging
    context.log((String) EasyMock.anyObject());
    EasyMock.expectLastCall().anyTimes();
    // run the test
    mockControl.replay();
    GatewayForwardingServlet servlet = new GatewayForwardingServlet();
    servlet.init(config);
    servlet.service(request, response);
    mockControl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestDispatcher(javax.servlet.RequestDispatcher) Test(org.junit.Test)

Example 67 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.

the class LoginController method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Login.jsp");
    dispatcher.forward(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 68 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.

the class ProfileController method doPost.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // get parameters
    String email = request.getParameter("email");
    String ps = request.getParameter("password");
    Connection c = null;
    try {
        String url = "jdbc:mysql://cs3.calstatela.edu/cs3220stu49";
        String username = "cs3220stu49";
        String password = "#Enwva2#";
        c = DriverManager.getConnection(url, username, password);
        // change name of database
        String sql = "select * from Users2 where email = ? and password = ?";
        PreparedStatement pstmt = c.prepareStatement(sql);
        pstmt.setString(1, email);
        pstmt.setString(2, ps);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Profile.jsp");
            dispatcher.forward(request, response);
            return;
        }
        response.sendRedirect("Login");
        return;
    } catch (SQLException e) {
        throw new ServletException(e);
    } finally {
        try {
            if (c != null)
                c.close();
        } catch (SQLException e) {
            throw new ServletException(e);
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 69 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project SEL-Student-Exchange-Library by jrojas10.

the class SignUpController method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/SignUp.jsp");
    dispatcher.forward(request, response);
}
Also used : RequestDispatcher(javax.servlet.RequestDispatcher)

Example 70 with RequestDispatcher

use of javax.servlet.RequestDispatcher in project iaf by ibissource.

the class Download method doGet.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    HttpSession session = request.getSession();
    if (session != null) {
        String url = (String) session.getAttribute(URL_KEY);
        if (url != null) {
            String parameters = null;
            Map params = (Map) session.getAttribute(PARAMETERS_KEY);
            for (Iterator it = params.keySet().iterator(); it.hasNext(); ) {
                String name = (String) it.next();
                String[] values = (String[]) params.get(name);
                for (int i = 0; i < values.length; i++) {
                    if (parameters == null) {
                        parameters = "?";
                    } else {
                        parameters += "&";
                    }
                    parameters += name + "=" + URLEncoder.encode(values[i], response.getCharacterEncoding());
                }
            }
            if (parameters != null) {
                url += parameters;
            }
            String context = request.getContextPath();
            if (url.startsWith(context)) {
                url = url.substring(context.length());
            }
            url = response.encodeURL(url);
            if (log.isDebugEnabled())
                log.debug("dispatching to [" + url + "]");
            String contenttype = (String) session.getAttribute(CONTENTTYPE_KEY);
            String filename = (String) session.getAttribute(FILENAME_KEY);
            session.removeAttribute(URL_KEY);
            session.removeAttribute(PARAMETERS_KEY);
            session.removeAttribute(CONTENTTYPE_KEY);
            session.removeAttribute(FILENAME_KEY);
            response.setContentType(contenttype);
            response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
            RequestDispatcher rd = request.getRequestDispatcher(url);
            rd.include(request, response);
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) Iterator(java.util.Iterator) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) 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