List of usage examples for javax.servlet RequestDispatcher include
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:org.owasp.benchmark.testcode.BenchmarkTest01846.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01846", "someSecret"); userCookie.setMaxAge(60 * 3); //Store cookie for 3 minutes userCookie.setSecure(true);/*w ww . jav a 2s . c o m*/ userCookie.setPath(request.getRequestURI()); response.addCookie(userCookie); javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/hash-02/BenchmarkTest01846.html"); rd.include(request, response); }
From source file:org.jboss.dashboard.ui.config.TreeActionsHandler.java
public CommandResponse actionShowTreePage(CommandRequest request) { RequestDispatcher rd = request.getRequestObject().getRequestDispatcher("/configuration/tree/tree.jsp"); try {//from w w w. j a va 2 s . c o m rd.include(request.getRequestObject(), request.getResponseObject()); } catch (Exception e) { log.error("Error:", e); try { request.getResponseObject().sendError(500); } catch (IOException e1) { log.error("Error:", e1); } } return new DoNothingResponse(); }
From source file:org.owasp.benchmark.testcode.BenchmarkTest01869.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { javax.servlet.http.Cookie userCookie = new javax.servlet.http.Cookie("BenchmarkTest01869", "whatever"); userCookie.setMaxAge(60 * 3); //Store cookie for 3 minutes userCookie.setSecure(true);/* w w w . j av a 2s . c o m*/ userCookie.setPath(request.getRequestURI()); response.addCookie(userCookie); javax.servlet.RequestDispatcher rd = request.getRequestDispatcher("/weakrand-04/BenchmarkTest01869.html"); rd.include(request, response); }
From source file:admin.AuthenticationServletTest.java
@Test public void test() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); HttpSession session = mock(HttpSession.class); RequestDispatcher rd = mock(RequestDispatcher.class); rd.include(request, response); ServletContext sc = mock(ServletContext.class); when(request.getParameter("action")).thenReturn("login"); when(request.getParameter("userName")).thenReturn("pmahend1"); when(request.getParameter("passWord")).thenReturn("pmahend1"); // when("url").thenReturn("/home.jsp"); //when(pool.getConnection()).thenReturn(connection); //when(request.getParameter("rememberMe")).thenReturn("Y"); when(request.getSession()).thenReturn(session); //when(request.getRequestDispatcher("/home.jsp")).thenReturn(rd); //when(request.getServletContext().getRequestDispatcher("/home.jsp")).thenReturn(rd); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); //when(response.getWriter()).thenReturn(pw); System.out.println("Step Test 1"); new AuthenticationServlet().doPost(request, response); System.out.println("Step Test 2"); List<Book> books = BookDB.selectAllBooks(); //Verify the session attribute value //verify(request).setAttribute("books", books); // request.setAttribute("books", books); //verify(rd).forward(request, response); verify(request, atLeast(1)).getParameter("action"); String result = sw.getBuffer().toString().trim(); System.out.println("Result: " + result); assertEquals("", result); }
From source file:com.gisgraphy.webapp.filter.StaticFilter.java
/** * This method checks to see if the current path matches includes or * excludes. If it matches includes and not excludes, it forwards to the * static resource and ends the filter chain. Otherwise, it forwards to the * next filter in the chain.// w w w. j ava 2s.c o m * * @param request * the current request * @param response * the current response * @param chain * the filter chain * @throws ServletException * when something goes wrong * @throws IOException * when something goes terribly wrong */ @Override public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { UrlPathHelper urlPathHelper = new UrlPathHelper(); String path = urlPathHelper.getPathWithinApplication(request); boolean pathExcluded = PatternMatchUtils.simpleMatch(excludes, path); boolean pathIncluded = PatternMatchUtils.simpleMatch(includes, path); if (pathIncluded && !pathExcluded) { if (logger.isDebugEnabled()) { logger.debug("Forwarding to static resource: " + path); } if (path.contains(".html")) { response.setContentType("text/html"); } RequestDispatcher rd = getServletContext().getRequestDispatcher(path); rd.include(request, response); return; } if (servletName != null) { RequestDispatcher rd = getServletContext().getNamedDispatcher(servletName); rd.forward(request, response); return; } chain.doFilter(request, response); }
From source file:com.agiletec.plugins.jpcontentfeedback.aps.tags.FeedbackIntroTag.java
@Override protected void includeWidget(RequestContext reqCtx, ResponseWrapper responseWrapper, Widget widget) throws ServletException, IOException { HttpServletRequest request = reqCtx.getRequest(); try {/*from w w w . j a v a2 s . c om*/ String actionPath = this.extractIntroActionPath(reqCtx, widget); if (!this.isStaticAction()) { String requestActionPath = request.getParameter(REQUEST_PARAM_ACTIONPATH); String currentFrameActionPath = request.getParameter(REQUEST_PARAM_FRAMEDEST); Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME); if (requestActionPath != null && currentFrameActionPath != null && currentFrame.toString().equals(currentFrameActionPath)) { if (this.isAllowedRequestPath(requestActionPath)) { actionPath = requestActionPath; } } } reqCtx.addExtraParam(EXTRAPAR_STATIC_ACTION, this.isStaticAction()); StringBuilder params = new StringBuilder(); // 1) widget 2) tag 3)request String contentId = null; if (null != this.getContentId()) { contentId = this.getContentId(); } if (null != contentId) { reqCtx.getRequest().setAttribute("currentContentId", contentId); } if (null != this.getReverseVotes() && this.getReverseVotes().equalsIgnoreCase("true")) { if (params.length() > 0) { params.append("&"); } params.append("reverseVotes=true"); } if (StringUtils.isNotBlank(this.getExtraParamsRedirect())) { String[] redirectParams = this.getExtraParamsRedirect().split(","); reqCtx.getRequest().setAttribute("extraParamNames", redirectParams); } actionPath = actionPath + "?" + params.toString(); RequestDispatcher requestDispatcher = request.getRequestDispatcher(actionPath); requestDispatcher.include(request, responseWrapper); } catch (Throwable t) { _logger.error("Error including widget ", t); RequestDispatcher requestDispatcher = request .getRequestDispatcher("/WEB-INF/aps/jsp/system/internalServlet_error.jsp"); requestDispatcher.include(request, responseWrapper); } }
From source file:org.account.RegisterServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w. j a v a 2 s. c o m*/ * * @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 { JSONObject jsonResponse = new JSONObject(); try { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String username = request.getParameter("username"); String email = request.getParameter("email"); String password = request.getParameter("password"); String name = request.getParameter("name"); String address = request.getParameter("address"); int postal = Integer.parseInt(request.getParameter("postal")); int number = Integer.parseInt(request.getParameter("number")); Connection con = DBConnect.connect(); PreparedStatement ps = con.prepareStatement( "INSERT INTO account(username,email,password,name,address,postal,number)values (?,?,?,?,?,?,?)"); ps.setString(1, username); ps.setString(2, email); ps.setString(3, password); ps.setString(4, name); ps.setString(5, address); ps.setInt(6, postal); ps.setInt(7, number); PreparedStatement dupecheck = con .prepareStatement("Select * from account where email = ? and password = ?"); dupecheck.setString(1, email); dupecheck.setString(2, password); ResultSet check = dupecheck.executeQuery(); if (!check.next()) { int i = ps.executeUpdate(); if (i > 0) { PreparedStatement newrec = con .prepareStatement("select * from account where email=? and password=?"); newrec.setString(1, email); newrec.setString(2, password); ResultSet res = newrec.executeQuery(); if (res.next()) { int retid = res.getInt("account_id"); jsonResponse.put("id", retid); jsonResponse.put("username", Login.findUsernamebyId(retid)); out.write(jsonResponse.toString()); out.flush(); } } else { out.println("Error Registration"); RequestDispatcher rs = request.getRequestDispatcher(""); rs.include(request, response); } } else { out.println("There is another same account" + ""); RequestDispatcher rs = request.getRequestDispatcher(""); rs.include(request, response); } } catch (ClassNotFoundException | SQLException ex) { Logger.getLogger(RegisterServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.knurt.ajajajava.control.ChangeLocation.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request/*from w ww . jav a 2 s . com*/ * @param response servlet response * @throws javax.servlet.ServletException * @throws java.io.IOException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { WebApplicationContext context = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); // get config objects Config config = (Config) context.getBean("config"); LocationPart locationPart = (LocationPart) context.getBean(request.getParameter("locationPart")); // set content type if (locationPart.getPartName().equals("javascript")) { response.setContentType("text/javascript;charset=" + Config.CHARSET); } else { response.setContentType("text/html;charset=" + Config.CHARSET); } Location location = this.getLocation(request, context); this.invokeAllAnnotatedMethods(location, request, context); RequestDispatcher dispatcher = this.getDispatcher(request, config, location, locationPart); dispatcher.include(request, response); }
From source file:ejportal.webapp.filter.StaticFilter.java
/** * This method checks to see if the current path matches includes or * excludes. If it matches includes and not excludes, it forwards to the * static resource and ends the filter chain. Otherwise, it forwards to the * next filter in the chain./*from w w w.j a v a 2 s . c o m*/ * * @param request * the current request * @param response * the current response * @param chain * the filter chain * @throws IOException * when something goes terribly wrong * @throws ServletException * when something goes wrong */ @Override public void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException { final UrlPathHelper urlPathHelper = new UrlPathHelper(); final String path = urlPathHelper.getPathWithinApplication(request); final boolean pathExcluded = PatternMatchUtils.simpleMatch(this.excludes, path); final boolean pathIncluded = PatternMatchUtils.simpleMatch(this.includes, path); if (pathIncluded && !pathExcluded) { if (this.logger.isDebugEnabled()) { this.logger.debug("Forwarding to static resource: " + path); } if (path.contains(".html")) { response.setContentType("text/html"); } final RequestDispatcher rd = this.getServletContext().getRequestDispatcher(path); rd.include(request, response); return; } if (this.servletName != null) { final RequestDispatcher rd = this.getServletContext().getNamedDispatcher(this.servletName); rd.forward(request, response); return; } chain.doFilter(request, response); }
From source file:Controller.login.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request// www . java2 s .c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); response.setContentType("text/html"); PrintWriter out = response.getWriter(); String email = request.getParameter("inputEmail"); String password = request.getParameter("inputPassword"); String remember = request.getParameter("remember"); System.out.println("remember ne mnow " + email); LoginImplementation loginCheckObject = new LoginImplementation(); JSONObject userData = (loginCheckObject.loginNow(email, password, remember)); System.out.println(userData); if (userData.has("error")) { RequestDispatcher rd = request.getRequestDispatcher("login.jsp"); request.setAttribute("loginError", "error"); rd.include(request, response); } else { if ("yes".equals(remember)) { System.out.println("apples"); HttpSession session = request.getSession(); session.setAttribute("user", userData); //setting session to expiry in 30 mins session.setMaxInactiveInterval(30 * 60); Cookie userName = new Cookie("user", email); userName.setMaxAge(30 * 60); response.addCookie(userName); } request.setAttribute("userData", userData); RequestDispatcher rd = request.getRequestDispatcher("views/home.jsp"); rd.forward(request, response); return; } out.close(); }