List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:Controller.ControllerProducts.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w . j av 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 { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { String action = request.getParameter("action"); if (action.equals("FIND")) { String productname = request.getParameter("txtname"); Products pr = new Products(); List<Product> list = new ArrayList<Product>(); list = pr.list(productname); request.setAttribute("listSP", list); request.setAttribute("proname", productname); RequestDispatcher rd = request.getRequestDispatcher("product.jsp"); rd.forward(request, response); } else if (action.equals("Delete")) { String code = request.getParameter("txtcode"); Products sp = new Products(); sp.Delete(code); RequestDispatcher rd = request.getRequestDispatcher("ControllerProducts?action=Find&txtname="); rd.forward(request, response); } else if (action.equals("Edit")) { String code = request.getParameter("txtcode"); String name = request.getParameter("txtname"); String price = request.getParameter("txtprice"); String image = request.getParameter("txtimage"); Product sp = new Product(code, name, price, image); request.setAttribute("SP", sp); RequestDispatcher rd = request.getRequestDispatcher("editProduct.jsp"); rd.forward(request, response); } else if (action.equals("Search")) { String productname = request.getParameter("txtname"); Products pr = new Products(); List<Product> list = new ArrayList<Product>(); list = pr.list(productname); request.setAttribute("listSP", list); request.setAttribute("proname", productname); RequestDispatcher rd = request.getRequestDispatcher("index.jsp"); rd.forward(request, response); } else if (action.equals("Searchcus")) { String productname = request.getParameter("txtname"); Products pr = new Products(); List<Product> list = new ArrayList<Product>(); list = pr.list(productname); request.setAttribute("listSP", list); request.setAttribute("proname", productname); RequestDispatcher rd = request.getRequestDispatcher("index_Cus1.jsp"); rd.forward(request, response); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tenduke.example.scribeoauth.oauth2.OAuth20LoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request/* w ww . j a va2s. co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // String idPUrl = provider.getAccessTokenEndpoint(); String callbackUrl = provider.getCallbackUrl(); // OAuth20ServiceImpl service = (OAuth20ServiceImpl) new ServiceBuilder().provider(provider) .apiKey(provider.getApiKey()).apiSecret(provider.getApiSecret()).scope("profile") .callback(provider.getCallbackUrl()).build(); // try { // String authzUrl = service.getAuthorizationUrl(OAuthConstants.EMPTY_TOKEN); response.sendRedirect(authzUrl); } catch (Throwable t) { // request.setAttribute("exception", t); request.getRequestDispatcher("/oauthError.jsp").forward(request, response); } }
From source file:com.mockey.ui.JsonSchemaValidateServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {//from w w w. j a va2s . c om Long serviceId = new Long(req.getParameter("serviceId")); Long scenarioId = null; scenarioId = new Long(req.getParameter("scenarioId")); Service service = store.getServiceById(serviceId); Scenario scenario = service.getScenario(scenarioId); req.setAttribute("service", service); req.setAttribute("scenario", scenario); } catch (Exception e) { logger.debug("Unable to retrieve a Service of ID: " + req.getParameter("serviceId")); } // Get the service. RequestDispatcher dispatch = req.getRequestDispatcher("/jsonschemavalidate.jsp"); dispatch.forward(req, resp); }
From source file:com.arcadian.loginservlet.CourseContentServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { contentService = new CourseContentService(); HttpSession session = request.getSession(); username = (String) session.getAttribute("username"); ArrayList alstClassName = contentService.getUserClass(username); request.setAttribute("alstClassName", alstClassName); ArrayList<CourseMaterialBean> alstCourseMaterial = contentService.fetchCourseMaterial(username); request.setAttribute("alstCourseMaterial", alstCourseMaterial); RequestDispatcher dispatcher = request.getRequestDispatcher("dashboard/coursecontent.jsp"); dispatcher.forward(request, response); }//from www . jav a 2s. co m }
From source file:io.github.benas.todolist.web.servlet.user.account.ChangePasswordServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String currentPassword = request.getParameter("currentPassword"); String newPassword = request.getParameter("newPassword"); String confirmationPassword = request.getParameter("confirmationPassword"); ChangePasswordForm changePasswordForm = new ChangePasswordForm(); changePasswordForm.setCurrentPassword(currentPassword); changePasswordForm.setNewPassword(newPassword); changePasswordForm.setConfirmationPassword(confirmationPassword); String nextPage = ACCOUNT_PAGE; validatePasswords(request, changePasswordForm); if (isInvalid(request)) { request.getRequestDispatcher(nextPage).forward(request, response); return;// ww w .j a v a 2 s . c om } HttpSession session = request.getSession(); User user = (User) session.getAttribute(TodoListUtils.SESSION_USER); if (!confirmationPassword.equals(newPassword)) { request.setAttribute("errorConfirmationPassword", resourceBundle.getString("account.password.confirmation.error")); addGlobalChangePasswordErrorAttribute(request); request.getRequestDispatcher(nextPage).forward(request, response); return; } if (!currentPassword.equals(user.getPassword())) { request.setAttribute("errorCurrentPassword", resourceBundle.getString("account.password.error")); addGlobalChangePasswordErrorAttribute(request); request.getRequestDispatcher(nextPage).forward(request, response); return; } user.setPassword(newPassword); userService.update(user); session.setAttribute(TodoListUtils.SESSION_USER, user); request.setAttribute("updatePasswordSuccessMessage", resourceBundle.getString("account.password.update.success")); request.getRequestDispatcher("/user/account").forward(request, response); }
From source file:io.github.benas.todolist.web.servlet.user.HomeServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(); User user = (User) session.getAttribute(TodoListUtils.SESSION_USER); List<Todo> todoList = todoService.getTodoListByUser(user.getId()); //todo list is request scoped to avoid storing and synchronizing it in session for each CRUD operation request.setAttribute("todoList", todoList); request.setAttribute("homeTabStyle", "active"); int totalCount = todoList.size(); int doneCount = TodoListUtils.countTotalDone(todoList); int todoCount = totalCount - doneCount; request.setAttribute("totalCount", totalCount); request.setAttribute("doneCount", doneCount); request.setAttribute("todoCount", todoCount); request.getRequestDispatcher(HOME_PAGE).forward(request, response); }
From source file:com.tenduke.example.scribeoauth.oauth10a.OAuth10aCallbackServlet.java
/** * <p>/* w ww . j av a2s .c o m*/ * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * </p> * <p> * Expects request parameters "oauth_token" and "oauth_verifier", which are used to resolve * request token and to further make access token request to the IdP. * </p> * * @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(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { // String tokenKeyFromRequest = request.getParameter("oauth_token"); String verifier = request.getParameter("oauth_verifier"); // OAuth10aProvider provider = new OAuth10aProvider(oauthConfig); OAuthService service = new ServiceBuilder().provider(provider).apiKey(provider.getApiKey()) .apiSecret(provider.getApiSecret()).build(); Token storedToken = RequestTokens.getRequestToken(tokenKeyFromRequest); // Token accessToken = service.getAccessToken(storedToken, new Verifier(verifier)); if (accessToken == null) { // request.getRequestDispatcher("/unauthorized.jsp").forward(request, response); } else { // JSONObject userInfo = graphMe(accessToken, provider); userInfo.put("accessToken", accessToken); userInfo.put("provider", provider); doLogin(request, response, userInfo); request.setAttribute("isOauth10a", true); request.setAttribute("userInfo", userInfo); request.getRequestDispatcher("/welcomeIn.jsp").forward(request, response); } }
From source file:Controller.FormCreatContenaire.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request//from w ww .ja v a 2 s .co m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ArrayList<String> templatesDefault = new ArrayList<String>(); ArrayList<String> templatesCustom = new ArrayList<String>(); templatesDefault = data.GetTemplatesDefault(); /* Rcupration de la session depuis la requte */ HttpSession webSession = request.getSession(); String user = (String) webSession.getAttribute(ATT_SESSION_EMAIL); System.out.println("***************USER : " + user); templatesCustom = data.GetTemplatesCustom(user); request.setAttribute("tempDefault", templatesDefault); request.setAttribute("tempCustom", templatesCustom); request.getRequestDispatcher("vmProfCreation.jsp").forward(request, response); }
From source file:com.parallax.server.blocklyprop.servlets.ProfileServlet.java
private void savePassword(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { User user = BlocklyPropSecurityUtils.getUserInfo(); req.setAttribute("email", user.getEmail()); req.setAttribute("screenname", user.getScreenname()); String oldPassword = req.getParameter("oldpassword"); String password = req.getParameter("password"); String confirmPassword = req.getParameter("confirmpassword"); if (Strings.isNullOrEmpty(oldPassword) || Strings.isNullOrEmpty(password) || Strings.isNullOrEmpty(confirmPassword)) { req.setAttribute("password-error", "Missing fields"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } else if (!password.equals(confirmPassword)) { req.setAttribute("password-error", "Passwords do not match"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } else {/* w w w. ja v a 2 s . com*/ try { if (cloudSessionLocalUserService.changePassword(BlocklyPropSecurityUtils.getCurrentSessionUserId(), oldPassword, password, confirmPassword)) { req.setAttribute("password-success", "Password changed"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } else { req.setAttribute("password-error", "Password could not be changed"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } } catch (UnknownUserIdException uuie) { req.setAttribute("password-error", "Unknown user"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } catch (PasswordVerifyException pve) { req.setAttribute("password-error", "Passwords did not match"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } catch (ServerException se) { req.setAttribute("base-error", "Server error"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } catch (PasswordComplexityException pce) { req.setAttribute("passwordComplexity", "Password is not complex enough"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } catch (WrongAuthenticationSourceException ex) { log.warn("Trying to change password of non local user!"); req.setAttribute("base-error", "Server error"); req.getRequestDispatcher("WEB-INF/servlet/profile/profile.jsp").forward(req, resp); } } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.java
protected void doForward(HttpServletRequest request, HttpServletResponse response, ResponseValues values) throws ServletException, IOException { String forwardUrl = values.getForwardUrl(); if (forwardUrl.contains("://")) { // It's a full URL, so redirect. response.sendRedirect(forwardUrl); } else {/*from w ww .jav a 2s .c om*/ // It's a relative URL, so forward within the application. request.getRequestDispatcher(forwardUrl).forward(request, response); } }