List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:de.uni_koeln.spinfo.maalr.webapp.i18n.InternationalUrlFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { //long start = System.nanoTime(); HttpServletRequest h = (HttpServletRequest) request; String uri = h.getRequestURI(); String path = h.getContextPath(); Locale userLocale = request.getLocale(); h.getSession().setAttribute("lang", userLocale.getLanguage()); String url = uri.substring(path.length()); /*/*w ww. j a v a 2 s . c o m*/ * Idee: die URL in ihre Bestandteile zerlegen und die einzelnen Teile * in einem Keyword-Tree matchen. Auf jeder Stufe wird dabei die eigentliche * URL um ein neues Element ergnzt. * * Funktioniert auf diese Weise gut fr statische URLs, aufbau eines Baums * fr URLs mit fest definierten Klassen (z.B. bersetzungsrichtung) ist ebenfalls mglich. * * Funktioniert aber nicht fr dynamische Bestandteile - da muss eine Wildcard * rein. * * :wrterbuch:deutsch-rumantsch:nase.html oder .json oder .xml * * Baum: * wrterbuch -> dictionary * deutsch-rumantsch -> tudesg->rumantsch * * -> * * ending * * Filter-Funktionalitt: * * a) Prfen, ob die URL schon in die Zielsprache bersetzt wurde. Falls ja: * doFilter() aufrufen, sonst bersetzen (andernfalls Endlos-Schleife). * * b) die gewhlte Sprache irgendwo in der Session hinterlegen, damit der * Rest des Programms (GUI) entsprechend der URL auch die richtigen Elemente * darstellt. * * c) Hilfsklasse notwendig, die URLs entsprechend der Sprache generiert, * z.B. fr dictionary (s.o.), aber auch fr "translate", einschlielich der * Durchblttern-Funktion. HTTP-GET sollte auch bersetzt werden (also Parameter-Namen), * POST nicht. * * d) Die Generierung des Baums darf lange dauern, die Abfrage muss aber * schnell sein - also z.B. Pattern.compile() beim Aufbau des Baums, nicht * beim Abfragen. * */ if ("/hilfe.html".equals(url) || "/help.html".equals(url)) { // change url and forward RequestDispatcher dispatcher = request.getRequestDispatcher("/agid.html"); // long end = System.nanoTime(); dispatcher.forward(request, response); } else { // long end = System.nanoTime(); chain.doFilter(request, response); } }
From source file:com.nova.geracao.portfolio.BlogServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // Entity newestPost = findNewestPost(); // if(newestPost == null){ // BlogPost post = new Gson().fromJson(post1, BlogPost.class); // Key<BlogPost> key = ObjectifyService.ofy().save().entity(post).now(); // }//w w w.j av a2 s.com String month = req.getParameter("month"); String tag = req.getParameter("tag"); String order = req.getParameter("order"); if (order != null) { String pid = req.getParameter("pid"); if (pid != null) { Long id = null; if ("prev".equalsIgnoreCase(order)) { id = Long.parseLong(pid) - 1; } else if ("next".equalsIgnoreCase(order)) { id = Long.parseLong(pid) + 1; } BlogPost result = ObjectifyService.ofy().load().type(BlogPost.class).id(id).now(); resp.getWriter().write(new Gson().toJson(result)); } else if ("last".equals(order)) { Iterable<Entity> result = findNewestPost(); if (result.iterator().hasNext()) { BlogPost post = (BlogPost) getInstanceFromPropertiesMap(result.iterator().next(), BlogPost.class); resp.getWriter().write(new Gson().toJson(post)); } } } else if (month != null) { Iterable<Entity> posts = findPostsByMonth(Integer.parseInt(month)); resp.getWriter().write(new Gson().toJson(posts)); } else if (tag != null) { Iterable<Entity> posts = findPostsByTag(tag); resp.getWriter().write(new Gson().toJson(posts)); } else { RequestDispatcher dispatcher = req.getRequestDispatcher("html/blog/index.html"); dispatcher.forward(req, resp); } }
From source file:Control.LoadImage.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from ww w . j a v a2s .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 doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { List<Image> images = loadImages(request, response); request.setAttribute("images", images); } catch (SQLException | ClassNotFoundException ex) { Logger.getLogger(LoadImage.class.getName()).log(Level.SEVERE, null, ex); } RequestDispatcher dispatcher = request.getRequestDispatcher("/LoadImage.jsp"); dispatcher.forward(request, response); }
From source file:edu.lternet.pasta.portal.DataPackageDeleteServlet.java
/** * The doPost method of the servlet. <br> * //from w ww. j av a 2 s . c o m * This method is called when a form has its tag value method equals to post. * * @param request * the request send by the client to the server * @param response * the response send by the server to the client * @throws ServletException * if an error occurred * @throws IOException * if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null || uid.isEmpty()) uid = "public"; String packageId = request.getParameter("packageid"); String scope = null; Integer identifier = null; String[] tokens = packageId.split("\\."); String message = null; try { if (uid.equals("public")) { message = LOGIN_WARNING; } else if (tokens.length == 2) { scope = tokens[0]; identifier = Integer.valueOf(tokens[1]); DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); dpmClient.deleteDataPackage(scope, identifier); message = "Data package with scope and identifier '<b>" + packageId + "</b>' has been deleted."; } else if (tokens.length == 3) { message = String.format( "The provided packaged identifier '%s' could not be parsed correctly. A revision value should not be included.", packageId); throw new UserErrorException(message); } else { message = String.format("The provided packaged identifier '%s' could not be parsed correctly.", packageId); throw new UserErrorException(message); } request.setAttribute("deletemessage", message); } catch (Exception e) { handleDataPortalError(logger, e); } RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:controller.deleteGame.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w . j a va 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"); try (PrintWriter out = response.getWriter()) { String Code = request.getParameter("Code"); Check c = new Check(); c.setCode(Code); int i = c.deleteGame(); if (i > 0) { RequestDispatcher rd = request.getRequestDispatcher("viewGames.jsp"); request.setAttribute("return", "Data deleted successfully."); rd.forward(request, response); } else { RequestDispatcher rd = request.getRequestDispatcher("deleteGame.jsp"); request.setAttribute("return", "Unable to delete data."); rd.forward(request, response); } } }
From source file:in.edu.ssn.servlet.BookingServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww.ja va 2 s. c om*/ * * @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 { //Car[] car = new Car[10]; CarStore carStore = new CarStoreMock(); String numplate = request.getParameter("nplate"); String reference1 = request.getParameter("reference"); int content1 = (Integer.parseInt(request.getParameter("content"))); System.out.println(numplate + reference1 + content1); Client client; client = ClientBuilder.newClient(); WebTarget target = client.target( "https://api.idolondemand.com/1/api/sync/addtotextindex/v1?json=%7B%22document%22%3A%7B%22title%22%3A%22" + numplate + "%22%2C%22reference%22%3A%22" + reference1 + "%22%2C%22content%22%3A%22" + content1 + "%22+%7D%7D&index=parkinglot&additional_metadata=&reference_prefix=&apikey=fa64dd8c-6193-47fd-a4ba-052939805fa4"); String response1 = target.request().get(String.class); org.json.JSONObject jsonObject = new org.json.JSONObject(response1); //JSONArray newJSON = jsonObject.getJSONArray("documents"); String c1n = new String(); //jsonObject = newJSON.getJSONObject(0); c1n = jsonObject.getString("index"); System.out.println(c1n); System.out.println(response); if (!(response1.isEmpty())) { //out.println("Booking confirm"); Car car = new Car(); if (carStore.findAllCars().size() == 10) { RequestDispatcher rd = request.getRequestDispatcher("/error.html"); rd.forward(request, response); } else { car.setCarNumber(numplate); car.setDuration(content1); carStore.create(car); } RequestDispatcher rd = request.getRequestDispatcher("/book.jsp"); rd.forward(request, response); // out.println("<div>"+response1+"<div>"); } else { RequestDispatcher rd = request.getRequestDispatcher("/error.html"); rd.forward(request, response); } /*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 BookingServlet</title>"); out.println("</head>"); out.println("<body>"); out.println(response1); out.println("</body>"); out.println("</html>");*/ } finally { out.close(); } }
From source file:mx.org.cedn.avisosconagua.engine.processors.Pronostico.java
@Override public void invokeForm(HttpServletRequest request, HttpServletResponse response, BasicDBObject data, String parts[]) throws ServletException, IOException { HashMap<String, String> datos = new HashMap<>(); String prevIssue = null;/*from w ww . j a va 2 s .c om*/ if (null != data) { for (String key : data.keySet()) { datos.put(key, data.getString(key)); //System.out.println("colocando: "+key+" : "+datos.get(key)); } } //Put nhcLinks in map BasicDBObject advice = MongoInterface.getInstance() .getAdvice((String) request.getSession(true).getAttribute("internalId")); if (null != advice) { //Get nhcLinks BasicDBObject section = (BasicDBObject) advice.get("precapture"); if (null != section) { datos.put("nhcForecastLink", section.getString("nhcForecastLink")); datos.put("nhcPublicLink", section.getString("nhcPublicLink")); prevIssue = section.getString("previousIssue"); } } //Advice without pronostico saved and for tracking if (advice != null && advice.get("pronostico") == null) { if (prevIssue != null) { BasicDBObject previous = MongoInterface.getInstance().getAdvice(prevIssue); if (previous != null) { //System.out.println("Putting previous data from "+prevIssue); BasicDBObject forecastSection = (BasicDBObject) previous.get("pronostico"); if (forecastSection != null) { //Set current values to previous values datos.put("issueSateliteLocationImgFooter", forecastSection.getString("issueSateliteLocationImgFooter", "")); } } } } request.setAttribute("data", datos); request.setAttribute("bulletinType", parts[2]); String url = "/jsp/forecast.jsp"; RequestDispatcher rd = request.getRequestDispatcher(url); rd.forward(request, response); }
From source file:com.gigglinggnus.controllers.AdminMakeAppointmentController.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()); request.setAttribute("exams", exams); RequestDispatcher rd = request.getRequestDispatcher("/admin/make-apmt.jsp"); rd.forward(request, response); }
From source file:fr.mby.saml2.sp.impl.web.Saml20ProcessingFilter.java
@Override public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { ServletRequest chainingRequest = request; if (HttpServletRequest.class.isAssignableFrom(request.getClass())) { final HttpServletRequest httpRequest = (HttpServletRequest) request; if (SamlHelper.isSamlResponse(httpRequest) || SamlHelper.isSamlRequest(httpRequest)) { // If it's a SAML 2.0 Response Saml20ProcessingFilter.LOGGER.debug("Start processing SAML 2.0 incoming request ..."); try { // Process SAML response final IIncomingSaml samlIncomingMsg = this.processSaml2Request(httpRequest); if (samlIncomingMsg != null) { final IQuery samlQuery = samlIncomingMsg.getSamlQuery(); Assert.notNull(samlQuery, "No SAML query found in IncomingSaml message !"); if (QueryAuthnResponse.class.isAssignableFrom(samlQuery.getClass())) { // The incoming message is a SAML Authn Response final QueryAuthnResponse authnResp = (QueryAuthnResponse) samlQuery; final QueryAuthnRequest authnReq = authnResp.getOriginalRequest(); Assert.notNull(authnReq, "No initial Authn Req request corresponding to SAML response found !"); // Retrieve initial params final Map<String, String[]> initialParams = authnReq.getParametersMap(); Assert.notNull(initialParams, "No initial params bound to the initial request !"); // Replace the request with the SAML 2.0 Response one. chainingRequest = new Saml20RequestWrapper(httpRequest, initialParams); }/*from ww w . j a v a 2 s . c om*/ } // Forward final RequestDispatcher requestDispatcher = chainingRequest.getRequestDispatcher("/login"); requestDispatcher.forward(chainingRequest, response); return; } catch (final Throwable e) { Saml20ProcessingFilter.LOGGER.error("Error while processing SAML 2.0 incoming request !", e); } } } chain.doFilter(chainingRequest, response); }
From source file:controller.servlet.AllDataDelete.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from ww w . j a va 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 { String page = "/pages/alldatadelete.jsp"; RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(page); requestDispatcher.forward(request, response); }