List of usage examples for javax.servlet RequestDispatcher forward
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException;
From source file:atd.home.BlogPost.java
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {// w w w . ja va 2s . c om Class.forName("org.apache.commons.lang3.StringEscapeUtils"); } catch (ClassNotFoundException e) { Logger.getLogger("atd.log").warning("Kan niet lib importeren"); e.printStackTrace(); } String bericht = req.getParameter("bericht"); java.util.Date dt = new java.util.Date(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = sdf.format(dt); User user = (User) req.getSession().getAttribute("username"); // Deze moet later verwerkt worden in KlantenBinding //BerichtenService.setBericht(StringEscapeUtils.escapeHtml4(bericht), currentTime, user); RequestDispatcher rd = null; Logger.getLogger("atd.log").info("Bericht: " + bericht + " door " + user.getNaam() + " is geplaatst"); rd = req.getRequestDispatcher("/index.jsp"); rd.forward(req, resp); }
From source file:eu.impact_project.wsclient.GeneratePages.java
/** * Uses the passed WSDL URL to analyze the WSDL for operations and * documentation. Retrieves empty SOAP messages for the operations using * SOAP UI libraries. Passes the information further to the displaying JSP. *//*from w w w .j a va2 s . c om*/ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession session = request.getSession(true); String fileName = null; String path = null; FileWriter file = null; File f; PrintWriter pw = null; InputStream in = null; OutputStream out = null; byte[] buf = new byte[1024]; int len; fileName = request.getParameter("wsId"); fileName = fileName.substring(fileName.lastIndexOf("/")); fileName = fileName.substring(fileName.lastIndexOf("/") + 1, fileName.lastIndexOf("?")); fileName = fileName + ".jsp"; path = request.getSession().getServletContext().getRealPath("/"); in = new FileInputStream(path + "interface.jsp"); out = new FileOutputStream(path + fileName); System.out.println("This is the input file: " + path + "interface.jsp"); System.out.println("This is the output file: " + path + fileName); while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } String wsdlURL = null; if (request.getParameter("wsId") != null) { wsdlURL = request.getParameter("wsId"); } else { // get WSDL file wsdlURL = request.getParameter("wsdlURL"); logger.trace("Importing WSDL from URL " + wsdlURL); } // get back to JSP RequestDispatcher rd = getServletContext().getRequestDispatcher("/" + fileName); rd.forward(request, response); }
From source file:sg.edu.ntu.hrms.web.action.UploadEmp.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. jav a2 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 { boolean hasAccess = false; response.setContentType("text/html;charset=UTF-8"); String action = request.getParameter("action"); System.out.println("action: " + action); HttpSession session = request.getSession(); HashMap accessTab = (HashMap) session.getAttribute("access"); AccessDTO access = (AccessDTO) accessTab.get("System Log"); if (access.getAccess() >= 1) { hasAccess = true; } if (!hasAccess) { RequestDispatcher dispatcher = request.getRequestDispatcher("/noAccess.jsp"); dispatcher.forward(request, response); } else { if (action == null || action.isEmpty()) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); //PriceDAO priceDAO = new PriceDAO(); WebApplicationContext ctx = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); try { List<FileItem> fields = upload.parseRequest(request); EmployeeEditService svc = (EmployeeEditService) ctx.getBean(EmployeeEditService.class); svc.uploadEmp(fields); } catch (Exception e) { e.printStackTrace(); } finally { //System.out.println("redirect to employee"); response.sendRedirect("employee.action"); /* RequestDispatcher dispatcher = request.getRequestDispatcher("/employee"); //request.setAttribute(Constants.TITLE, "Home"); dispatcher.forward(request, response); */ } } else { RequestDispatcher dispatcher = request.getRequestDispatcher("/uploadEmp.jsp"); //request.setAttribute(Constants.TITLE, "Home"); dispatcher.forward(request, response); } } }
From source file:com.ribas.andrei.web.DBDataServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { try {/*from ww w . java 2 s .c o m*/ Class.forName("org.h2.Driver"); Collection<DBSchema> dbSchemasRetrievedWithDefaultInitialContext = this .getDataFromDataSource(DataSourceUtils.getDataSourceByJNDI()); req.setAttribute("dbSchemasRetrievedWithDefaultInitialContext", dbSchemasRetrievedWithDefaultInitialContext); } catch (ClassNotFoundException | SQLException | NamingException e) { logAndCreateException(req, e); } finally { RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/dbSchemas.jsp"); try { dispatcher.forward(req, resp); } catch (IOException e) { logAndCreateException(req, e); } } }
From source file:org.carcv.web.servlet.CarTableServlet.java
/** * @see CarTableServlet/* w w w . ja v a 2 s .c o m*/ * @param request the HttpServletRequest * @param response the HttpServletResponse * @throws ServletException * @throws IOException */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final ArrayList<FileEntry> requestEntries = (ArrayList<FileEntry>) bean.getAll(); @SuppressWarnings("unchecked") ArrayList<FileEntry> abstractEntries = (ArrayList<FileEntry>) requestEntries.clone(); // Timezone String timeZoneStr = request.getParameter("timezone"); TimeZone tz = TimeZone.getTimeZone(timeZoneStr); DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy"); dateFormat.setTimeZone(tz); DateFormat timeFormat = new SimpleDateFormat("HH:mm"); timeFormat.setTimeZone(tz); Collections.sort(abstractEntries, new Comparator<FileEntry>() { @Override public int compare(FileEntry o1, FileEntry o2) { return new CompareToBuilder().append(o2.getCarData().getTimestamp(), o1.getCarData().getTimestamp()) .toComparison(); } }); String date, time, entryId, licensePlate, location, previewPath; ArrayList<WebReportTableMember> wrtmList = new ArrayList<>(); for (FileEntry e : abstractEntries) { // initialize date = dateFormat.format(e.getCarData().getTimestamp()); time = timeFormat.format(e.getCarData().getTimestamp()); entryId = e.getId().toString(); licensePlate = e.getCarData().getNumberPlate().getOrigin() + ": " + e.getCarData().getNumberPlate().getText(); location = e.getCarData().getAddress().printBR(); FileCarImage fci = e.getCarImages().get(0); previewPath = fci.getFilepath().toString(); WebReportTableMember wrtm = new WebReportTableMember(previewPath, entryId, time, date, location, licensePlate, timeZoneStr); wrtmList.add(wrtm); } request.setAttribute("wrtmList", wrtmList); boolean isAdmin = request.isUserInRole(adminRole); request.setAttribute("isAdmin", isAdmin); RequestDispatcher rd = getServletContext().getRequestDispatcher("/app/cartable.jsp"); rd.forward(request, response); }
From source file:in.edu.ssn.servlet.VerifyServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w .j a v a 2 s . 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"); PrintWriter out = response.getWriter(); try { String numplate = request.getParameter("nplate"); System.out.println(numplate); Client client; client = ClientBuilder.newClient(); WebTarget target = client.target("https://api.idolondemand.com/1/api/sync/querytextindex/v1?text=" + numplate + "&indexes=&indexes=parkinglot&print=reference&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(); if (newJSON.isNull(0)) { response.sendRedirect("error1.html"); } else { jsonObject = newJSON.getJSONObject(0); c1n = jsonObject.getString("title"); //Object c=c1n; System.out.println("hi" + c1n); CarStoreMock csm = new CarStoreMock(); List<Car> allcars = csm.findAllCars(); // List<String> list = new ArrayList<String>(); //list.add(c1n); for (Car car : allcars) { System.out.println("Hello" + car); if (car.getCarNumber().equalsIgnoreCase(c1n)) { System.out.print("success"); //out.println("Booking confirm"); RequestDispatcher rd = request.getRequestDispatcher("/allow.jsp"); rd.forward(request, response); // out.println("<div>"+response1+"<div>"); } else { RequestDispatcher rd = request.getRequestDispatcher("/error1.html"); rd.forward(request, response); } } // System.out.println(allcars.toArray(new String[0])); // System.out.println("string value"+allcars.toString()); } } finally { out.close(); } }
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); }/*ww w . ja v a2 s . c om*/ }
From source file:com.happyuno.controller.JoinGameTable.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=utf-8"); request.setCharacterEncoding("utf-8"); //?/*from w w w . jav a 2 s. co m*/ String tableId = (String) request.getParameter("tableId"); // int tableId =Integer.parseInt(request.getSession().getAttribute("tableId").toString()); // String setNum = request.getParameter("setNum").trim(); // ServletContext application = request.getSession().getServletContext(); HashMap<Integer, GameTable> gameTableMap = (HashMap<Integer, GameTable>) application .getAttribute("gameTableMap"); //?ID user String userId = (String) request.getSession().getAttribute("userId"); maindeal md = new maindeal(); List dbUserList = md.query("from User as u where u.id='" + userId + "'"); User curUser = (User) dbUserList.get(0); // String resultMessage = "?"; int index = Integer.parseInt(tableId); System.out.println(index); // GameTable gametable = gameTableMap.get(index); if (gametable == null) { System.out.println("true"); } int defiNum = gametable.getDefiNum(); // if (gametable.isStateStart() == false) { //? if (gametable.getUserList().size() < defiNum) { //?? if (!gametable.getUserList().contains(curUser)) { gametable.getUserList().add(curUser); } resultMessage = "??"; } else { resultMessage = "???"; } } else { resultMessage = "????"; } // application.setAttribute("gameTableMap", gameTableMap); //?? HttpSession session = request.getSession(); session.setAttribute("tableId", index); session.setAttribute("userList", gameTableMap.get(index).getUserList()); RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/waiting.jsp"); dispatcher.forward(request, response); // PrintWriter out = response.getWriter(); // out.print("ID"); // out.println(userId); // out.print("?:"); // out.println(resultMessage); // out.print("?"); // out.println(gametable.getUserList().size()); }
From source file:edu.lternet.pasta.portal.RevisionBrowseServlet.java
/** * The doPost method of the servlet. <br> * /*from w ww . j av a2s . co 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 scope = request.getParameter("scope"); String identifier = request.getParameter("identifier"); Integer id = Integer.valueOf(identifier); String text = null; String html = null; Integer count = 0; try { if (scope != null && !(scope.isEmpty()) && identifier != null && !(identifier.isEmpty())) { DataPackageManagerClient dpmClient = new DataPackageManagerClient(uid); text = dpmClient.listDataPackageRevisions(scope, id, null); StrTokenizer tokens = new StrTokenizer(text); html = "<ol>\n"; while (tokens.hasNext()) { String revision = tokens.nextToken(); html += "<li><a class=\"searchsubcat\" href=\"./mapbrowse?scope=" + scope + "&identifier=" + identifier + "&revision=" + revision + "\">" + scope + "." + identifier + "." + revision + "</a></li>\n"; count++; } html += "</ol>\n"; } else { String msg = "The 'scope', 'identifier', or 'revision' field of the packageId is empty."; throw new UserErrorException(msg); } } catch (Exception e) { handleDataPortalError(logger, e); } request.setAttribute("browsemessage", browseMessage); request.setAttribute("html", html); request.setAttribute("count", count.toString()); RequestDispatcher requestDispatcher = request.getRequestDispatcher(forward); requestDispatcher.forward(request, response); }
From source file:controller.servlet.ImportAmenities.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*ww w. ja va2s. 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 { String page = "/pages/importingamenities.jsp"; RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher(page); requestDispatcher.forward(request, response); }