List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.lrodriguez.SVNBrowser.java
private void doBrowserRevisionQuery(HttpServletRequest request, HttpServletResponse response, HttpSession session, String pFileType, String currentBranch, Comparator comparator) throws ServletException, IOException { logDebug("Dispatching Browser Revision query"); logDebug("dispatching Revision query request"); List uniqueEntries = getUniqueEntries(request, Long.parseLong(request.getParameter(START_REVISION)), Long.parseLong(request.getParameter(END_REVISION))); if (request.getAttribute(ERROR) != null) { request.getRequestDispatcher(INDEX_JSP).forward(request, response); return;/* w ww . j a v a 2 s. c o m*/ } uniqueEntries = filterListByFileType(uniqueEntries, pFileType); uniqueEntries = filterListByCurrentBranch(uniqueEntries, currentBranch); Collections.sort(uniqueEntries, comparator); session.setAttribute(UNIQUE_ENTRIES, uniqueEntries); request.getRequestDispatcher(INDEX_JSP).forward(request, response); }
From source file:com.gigglinggnus.controllers.ManageExamsController.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { EntityManager em = (EntityManager) request.getSession().getAttribute("em"); Clock clk = (Clock) (request.getSession().getAttribute("clock")); List<Term> terms = Term.getFutureTerms(em, Instant.now(clk)); List<Exam> exams = terms.stream().flatMap(term -> term.getExams().stream()) .filter(exam -> exam.getStatus() == ExamStatus.PENDING).collect(Collectors.toList()); Map<Exam, ArrayList<String>> utilMap = new HashMap(); for (Exam e : exams) { Interval<Instant> examInt = e.getInterval(); LocalDate testDate = examInt.getStart().atZone(ZoneId.systemDefault()).toLocalDate(); LocalDate endDate = examInt.getEnd().atZone(ZoneId.systemDefault()).toLocalDate(); Term t = e.getTerm();/*from w w w. ja va 2 s .c o m*/ Map<LocalDate, Long> examUtilMap = new HashMap(); ArrayList<String> examList = new ArrayList(); while (testDate.isBefore(endDate.plusDays(1))) { examList.add(testDate.toString() + "=" + t.utilizationForDay(testDate, clk) + " "); testDate = testDate.plusDays(1); } utilMap.put(e, examList); } request.setAttribute("exams", exams); request.setAttribute("utilList", utilMap); RequestDispatcher rd = request.getRequestDispatcher("/admin/manage-exams.jsp"); rd.forward(request, response); }
From source file:Service.java
/** * When the servlet receives a POST request. *//*from ww w . j a va2s . co m*/ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String forward = ""; // Which jsp page is going to be return. String eurosentiment = ""; // This is the analysis response. // Auxiliar variables. HttpEntity entity = null; HttpSession session = request.getSession(); RequestDispatcher view; // Get a map of the request parameters Map parameters = request.getParameterMap(); if (parameters.containsKey("input")) { // If the request contains a parameter named input if (parameters.containsKey("intype") && parameters.containsKey("informat") && parameters.containsKey("outformat")) { // If the request contains a parameter named intype, informat and outformat. if (!request.getParameter("intype").equalsIgnoreCase("direct")) { // If intype is not direct. // The response contains only the following message. forward = RESPONSE_JSP; eurosentiment = "intype should be direct"; session.setAttribute("eurosentiment", eurosentiment); view = request.getRequestDispatcher(forward); view.forward(request, response); return; } if (!request.getParameter("informat").equalsIgnoreCase("text")) { // If informat is not text // The response contains only the following message. forward = RESPONSE_JSP; eurosentiment = "informat should be text"; session.setAttribute("eurosentiment", eurosentiment); view = request.getRequestDispatcher(forward); view.forward(request, response); return; } if (!request.getParameter("outformat").equalsIgnoreCase("json-ld")) { // If outformat is not json-ld // The response contains only the following message. forward = RESPONSE_JSP; eurosentiment = "outformat should be json-ld"; session.setAttribute("eurosentiment", eurosentiment); view = request.getRequestDispatcher(forward); view.forward(request, response); return; } // If there is input, intype = direct, informat = text and outformat = json-ld, forward = RESPONSE_JSP; // response.jsp String textToAnalize = request.getParameter("input"); // Text to be analyzed. try { if (parameters.containsKey("algo")) { // If the request contains a parameter named algo (algorithm) if (request.getParameter("algo").equalsIgnoreCase("spFinancial")) { // If algo = spFinancial entity = callSAGA(textToAnalize, "spFinancial"); // The corresponding GATE module is called and a MARL entity is generated. } else if (request.getParameter("algo").equalsIgnoreCase("emoticon")) { // If algo = Emoticon entity = callSAGA(textToAnalize, "emoticon"); // The corresponding GATE module is called and a MARL entity is generated. } else if (request.getParameter("algo").equalsIgnoreCase("spFinancialEmoticon")) { // If algo = spFinancialEmoticon entity = callSAGA(textToAnalize, "spFinancialEmoticon"); // The corresponding GATE module is called and a MARL entity is generated. } else { // If the request contains a non-valid algorithm. forward = RESPONSE_JSP; eurosentiment = "Introduce a valid algorithm"; session.setAttribute("eurosentiment", eurosentiment); view = request.getRequestDispatcher(forward); view.forward(request, response); return; } } // If a GATE module has been called and a MARL entity has been generated. if (entity != null) { // The MARL entity is processed to be added to the response.jsp InputStream instream = entity.getContent(); try { // The entity is parsed into a StringBuffer. BufferedReader in = new BufferedReader(new InputStreamReader(instream)); String inputLine; StringBuffer marl = new StringBuffer(); while ((inputLine = in.readLine()) != null) { marl.append(inputLine); marl.append("\n"); } in.close(); // The variable eurosentiment (String) is setted with the MARL response. eurosentiment = marl.toString(); session.setAttribute("eurosentiment", eurosentiment); } finally { instream.close(); } } } catch (Exception e) { System.err.println(e); } } else { // If there is no intype, informat or outformat specified. forward = RESPONSE_JSP; eurosentiment = "There is no intype, informat or outformat specified"; session.setAttribute("eurosentiment", eurosentiment); } } else { // If there is no input. forward = RESPONSE_JSP; eurosentiment = "There is no input"; session.setAttribute("eurosentiment", eurosentiment); } view = request.getRequestDispatcher(forward); view.forward(request, response); }
From source file:demo.web.doAGoodActionServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w. j av a2s. com*/ * * @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()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet dokkkkAGoodActionServlet</title>"); out.println("</head>"); out.println("<body>"); out.println("<h1>Servlet doAGoodAdssfsdfctionServlet at " + request.getContextPath() + "</h1>"); out.println("</body>"); out.println("</html>"); JSONObject json = new JSONObject(); json.put("description", "Une_app_de_test"); json.put("name", "MyTest"); json.put("password", "password"); HttpClient httpClient = HttpClientBuilder.create().build(); //Use this instead HttpPost requestHttpPost; String addresse = "http://localhost:8090/api"; requestHttpPost = new HttpPost(addresse + "/applications"); StringEntity params = new StringEntity(json.toString()); requestHttpPost.addHeader("content-type", "application/json"); requestHttpPost.setEntity(params); HttpResponse responseHttpResponse = httpClient.execute(requestHttpPost); request.getRequestDispatcher("WEB-INF/pages/login.jsp").forward(request, response); } }
From source file:com.netcracker.financeapp.controller.spending.SpendingServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int value = Integer.parseInt(request.getParameter("value")); String from = request.getParameter("fromListVal"); BankCard currentBankCard = bankCardService.getBankCardByNumber(from); if (currentBankCard.getAmount() > value) { bankCardService.editCardAmount(currentBankCard.getIdCard(), currentBankCard.getAmount() - value); String to = request.getParameter("toListVal"); Agent currentAgent = agentService.getAgentByName(to); Date date = null;//from ww w .ja v a2 s.com try { DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy"); date = dateFormat.parse(request.getParameter("date")); } catch (ParseException ex) { Logger.getLogger(SpendingServlet.class.getName()).log(Level.SEVERE, null, ex); } String description = request.getParameter("description"); String typeName = request.getParameter("spendingType"); int typeId = typeService.getTypeByName(typeName).getIdType(); int transactionTypeId = typeService.getTypeByName(typeName).getIdParent(); int stateTypeId = typeService.getTypeByName("COMMITED").getIdType(); int spendingId = spendingService.insertSpending(value, description, date, typeId); if (spendingId > 0) { request.getRequestDispatcher("templates/success.jsp").forward(request, response); transactionService.insertTransaction(transactionTypeId, stateTypeId, currentAgent.getIdAgent(), currentBankCard.getIdCard(), spendingId); } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } } else { request.getRequestDispatcher("templates/error.jsp").forward(request, response); } }
From source file:com.alfaariss.oa.sso.web.profile.logout.LogoutProfile.java
private void showConfirmJSP(HttpServletRequest servletRequest, HttpServletResponse servletResponse, ISession session, List<IRequestor> listRequestors, IRequestor requestor) throws OAException { try {// w ww . j a va 2 s . co m servletRequest.setAttribute(ISession.ID_NAME, session.getId()); servletRequest.setAttribute("requestors", listRequestors); servletRequest.setAttribute("requestor", requestor); servletRequest.setAttribute("user", session.getUser()); //Set server info as attribute servletRequest.setAttribute(Server.SERVER_ATTRIBUTE_NAME, Engine.getInstance().getServer()); //Forward to page RequestDispatcher oDispatcher = servletRequest.getRequestDispatcher(_sJSPConfirmation); if (oDispatcher != null) oDispatcher.forward(servletRequest, servletResponse); else { _logger.fatal("Forward request not supported"); throw new OAException(SystemErrors.ERROR_INTERNAL); } } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during jsp forward", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } }
From source file:eu.eidas.springsecu.EidasAccessDeniedHandler.java
@Override public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { logger.debug("Arrive dans handle error"); EIDASAuthnResponse authnResponse = null; SAMLResponse = request.getParameter("SAMLresponse"); if (SAMLResponse == null) { throw new IOException("Saml Response is null"); }/*from w ww . j a v a 2 s . c om*/ if (SAMLResponse.isEmpty()) { throw new IOException("Saml Response is empty"); } //Decodes SAML Response byte[] decSamlToken = EIDASUtil.decodeSAMLToken(SAMLResponse); //Get SAMLEngine instance try { EIDASSAMLEngine engine = SPUtil.createSAMLEngine(Constants.SP_CONF); //validate SAML Token authnResponse = engine.validateEIDASAuthnResponse(decSamlToken, request.getRemoteHost(), 0); } catch (EIDASSAMLEngineException e) { logger.error(e.getMessage()); if (StringUtils.isEmpty(e.getErrorDetail())) { throw new IOException(SAML_VALIDATION_ERROR, e); } else { throw new IOException(SAML_VALIDATION_ERROR, e); } } if (authnResponse.isFail()) { throw new IOException("Saml Response is fail" + authnResponse.getMessage()); } else { request.setAttribute("assertions", authnResponse.getAsserts()); RequestDispatcher dispatch; dispatch = request.getRequestDispatcher("/saml"); logger.debug("Avant forward vers saml"); dispatch.forward(request, response); } }
From source file:org.eclipse.packagedrone.repo.channel.web.channel.ChannelController.java
@Secured(false) @RequestMapping(value = "/channel/{channelId}/view", method = RequestMethod.GET) @HttpConstraint(PERMIT)/* ww w . j a v a2 s .c om*/ public ModelAndView view(@PathVariable("channelId") final String channelId, final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final Optional<ChannelInformation> channel = this.channelService.getState(By.name(channelId)); if (channel.isPresent()) { return new ModelAndView(String.format("redirect:/channel/%s/view", channel.get().getId())); } else { request.getRequestDispatcher("tree").forward(request, response); return null; } }
From source file:com.edgenius.wiki.webapp.servlet.InstallServlet.java
private boolean checkDowngrade(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Installation install = Installation.refreshInstallation(); int installVer = (int) (NumberUtils.toFloat(install.getVersion(), 1f) * 1000); int appVer = (int) (NumberUtils.toFloat(Version.VERSION, 1f) * 1000); if (installVer > appVer) { Installation.DONE = false;//from w w w. j a va 2 s.c om //application version is lower than existed data version, stop further test request.setAttribute("appVer", Version.VERSION); request.setAttribute("installVer", install.getVersion()); request.getRequestDispatcher("/WEB-INF/pages/install/lower-appversion.jsp").forward(request, response); return true; } return false; }
From source file:auth.ProcessResponseServlet.java
/** * The doGet method handles HTTP GET requests sent to the * ProcessResponseServlet. This method's sole purpose is to interact with the * user interface that allows you to walk through the steps of the reference * implementation. In a production environment, Google's would send SAML * requests using HTTP redirect.// w w w . j av a 2 s . co m * * This method receives an HTTP GET request and then forwards that request on * to the identity_provider.jsp file, which is included in Google's SAML * reference package. If this method receives a SAML request Read in SAML * AuthnRequest parameters from request and generate signed SAML response to * post to the Assertion Consumer Service. */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String SAMLRequest = request.getParameter("SAMLRequest"); String relayStateURL = request.getParameter("RelayState"); if (SAMLRequest != null) { try { String requestXmlString = decodeAuthnRequestXML(SAMLRequest); String[] samlRequestAttributes = getRequestAttributes(requestXmlString); String issueInstant = samlRequestAttributes[0]; String providerName = samlRequestAttributes[1]; String acsURL = samlRequestAttributes[2]; String requestId = samlRequestAttributes[3]; request.setAttribute("issueInstant", issueInstant); request.setAttribute("providerName", providerName); request.setAttribute("acsURL", acsURL); request.setAttribute("requestId", requestId); request.setAttribute("relayStateURL", relayStateURL); } catch (SamlException e) { request.setAttribute("error", e.getMessage()); } } String returnPage = "./googleSaml.jsp"; request.getRequestDispatcher(returnPage).include(request, response); }