List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:in.edu.ssn.servlet.VerifyServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from www.jav 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 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:cpabe.controladores.UploadDownloadFileAdvancedServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!ServletFileUpload.isMultipartContent(request)) { throw new ServletException("Content type is not multipart/form-data"); }//from w w w .j a va 2 s. c om // response.setContentType("text/html"); // PrintWriter out = response.getWriter(); // out.write("<html><head></head><body>"); try { List<FileItem> fileItemsList = uploader.parseRequest(request); Iterator<FileItem> fileItemsIterator = fileItemsList.iterator(); while (fileItemsIterator.hasNext()) { FileItem fileItem = fileItemsIterator.next(); System.out.println("FieldName=" + fileItem.getFieldName()); System.out.println("FileName=" + fileItem.getName()); System.out.println("ContentType=" + fileItem.getContentType()); System.out.println("Size in bytes=" + fileItem.getSize()); File file = new File(request.getServletContext().getAttribute("FILES_DIR") + File.separator + fileItem.getName()); //setar no objeto CaminhoArquivo os dados do arquivo anexado String caminho = file.getAbsolutePath(); String nome = fileItem.getName(); CaminhoArquivo c = new CaminhoArquivo(); c.setNome(nome); c.setWay(caminho); request.setAttribute("caminho", c); System.out.println("caminho=" + caminho); System.out.println("nome=" + nome); System.out.println("Absolute Path at server=" + file.getAbsolutePath()); fileItem.write(file); request.getRequestDispatcher("/avancado/encriptar/encriptar1.jsp").forward(request, response); // out.write("File " + fileItem.getName() + " uploaded successfully."); // out.write("<br>"); // out.write("<a href=\"UploadDownloadFileServlet?fileName=" + fileItem.getName() + "\">Download " + fileItem.getName() + "</a>"); } } catch (FileUploadException e) { // out.write("Exception in uploading file."); } catch (Exception e) { // out.write("Exception in uploading file."); } // out.write("</body></html>"); }
From source file:cpabe.controladores.UploadDownloadFileServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (!ServletFileUpload.isMultipartContent(request)) { throw new ServletException("Content type is not multipart/form-data"); }// ww w .j a v a 2 s. c om // response.setContentType("text/html"); // PrintWriter out = response.getWriter(); // out.write("<html><head></head><body>"); try { List<FileItem> fileItemsList = uploader.parseRequest(request); Iterator<FileItem> fileItemsIterator = fileItemsList.iterator(); while (fileItemsIterator.hasNext()) { FileItem fileItem = fileItemsIterator.next(); System.out.println("FieldName=" + fileItem.getFieldName()); System.out.println("FileName=" + fileItem.getName()); System.out.println("ContentType=" + fileItem.getContentType()); System.out.println("Size in bytes=" + fileItem.getSize()); File file = new File(request.getServletContext().getAttribute("FILES_DIR") + File.separator + fileItem.getName()); //setar no objeto CaminhoArquivo os dados do arquivo anexado String caminho = file.getAbsolutePath(); String nome = fileItem.getName(); CaminhoArquivo c = new CaminhoArquivo(); c.setNome(nome); c.setWay(caminho); request.setAttribute("caminho", c); System.out.println("caminho=" + caminho); System.out.println("nome=" + nome); System.out.println("Absolute Path at server=" + file.getAbsolutePath()); fileItem.write(file); request.getRequestDispatcher("/formularios/encriptar/encriptar1.jsp").forward(request, response); // out.write("File " + fileItem.getName() + " uploaded successfully."); // out.write("<br>"); // out.write("<a href=\"UploadDownloadFileServlet?fileName=" + fileItem.getName() + "\">Download " + fileItem.getName() + "</a>"); } } catch (FileUploadException e) { // out.write("Exception in uploading file."); } catch (Exception e) { // out.write("Exception in uploading file."); } // out.write("</body></html>"); }
From source file:com.bibisco.servlet.BibiscoServlet.java
public void openLanguage(HttpServletRequest pRequest, HttpServletResponse pResponse) throws ServletException, IOException { mLog.debug("Start openLanguage(HttpServletRequest, HttpServletResponse)"); pRequest.getRequestDispatcher(LANGUAGE).forward(pRequest, pResponse); mLog.debug("End openLanguage(HttpServletRequest, HttpServletResponse)"); }
From source file:com.bibisco.servlet.BibiscoServlet.java
public void openThumbnailStrands(HttpServletRequest pRequest, HttpServletResponse pResponse) throws ServletException, IOException { mLog.debug("Start openThumbnailStrands(HttpServletRequest, HttpServletResponse)"); pRequest.getRequestDispatcher(STRANDS).forward(pRequest, pResponse); mLog.debug("End openThumbnailStrands(HttpServletRequest, HttpServletResponse)"); }
From source file:edu.lternet.pasta.portal.DataPackageDeleteServlet.java
/** * The doPost method of the servlet. <br> * /*from ww w .j a va2s . 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:net.duckling.ddl.web.interceptor.access.VWBDenyListener.java
public void onDeny(HttpServletRequest request, HttpServletResponse response, RequirePermission requirePermission) throws IOException { VWBSession m_session = VWBSession.findSession(request); VWBContainer container = VWBContainerImpl.findContainer(); Principal currentUser = m_session.getCurrentUser(); try {/*from w w w . j ava2 s .com*/ if (m_session.isAuthenticated()) { LOGGER.info("User " + currentUser.getName() + " has no access - forbidden (permission=" + getRequiredPermission(requirePermission) + ") URL:" + request.getRequestURI()); response.setHeader("ddl-auth", "Permission dend"); response.sendError(HttpServletResponse.SC_FORBIDDEN); } else { LOGGER.info("User " + currentUser.getName() + " has no access - redirecting (permission=" + getRequiredPermission(requirePermission) + ") URL:" + request.getRequestURI()); String requesturl = (String) request.getAttribute(Attributes.REQUEST_URL); if (requesturl == null) { requesturl = getRequestURL(request); } m_session.setAttribute(Attributes.REQUEST_URL, requesturl); m_session.setAttribute(Attributes.TEAM_ID_FOR_JOIN_PUBLIC_TEAM, request.getParameter("teamId")); if (isAjaxRequest(request)) { response.setStatus(450); } else { if (isHashURL(requesturl)) { m_session.removeAttribute(Attributes.REQUEST_URL); request.setAttribute("url", UrlUtil.changeSchemeToHttps( container.getURL(UrlPatterns.LOGIN, null, null, false), request)); request.getRequestDispatcher("/jsp/aone/hash/dealHashRequest.jsp").forward(request, response); } else { String redirect = UrlUtil.changeSchemeToHttps( container.getURL(UrlPatterns.LOGIN, null, null, false), request); response.sendRedirect(redirect); } } } } catch (IOException e) { LOGGER.error("Redirect failed for:" + e.getMessage(), e); throw new InternalVWBException(e.getMessage()); } catch (ServletException e) { LOGGER.error("Redirect failed for:" + e.getMessage(), e); throw new InternalVWBException(e.getMessage()); } }
From source file:com.alfaariss.oa.util.saml2.binding.post.JSPHTTPPostEncoder.java
private void postEncode(SAMLMessageContext messageContext, String endpointURL) throws MessageEncodingException { InTransport inTransport = messageContext.getInboundMessageTransport(); HttpServletRequest request = ((HttpServletRequestAdapter) inTransport).getWrappedRequest(); OutTransport outTransport = messageContext.getOutboundMessageTransport(); HttpServletResponse response = ((HttpServletResponseAdapter) outTransport).getWrappedResponse(); HTTPOutTransport out = (HTTPOutTransport) messageContext.getOutboundMessageTransport(); HTTPTransportUtils.addNoCacheHeaders(out); HTTPTransportUtils.setUTF8Encoding(out); request.setAttribute("action", endpointURL); if (messageContext.getOutboundSAMLMessage().getDOM() == null) { marshallMessage(messageContext.getOutboundSAMLMessage()); }/*from w w w .j a va2 s . co m*/ String messageXML = XMLHelper.nodeToString(messageContext.getOutboundSAMLMessage().getDOM()); try { String encodedMessage = Base64.encodeBytes(messageXML.getBytes(SAML2Constants.CHARSET), Base64.DONT_BREAK_LINES); if (messageContext.getOutboundSAMLMessage() instanceof RequestAbstractType) { request.setAttribute("SAMLRequest", encodedMessage); } else if (messageContext.getOutboundSAMLMessage() instanceof StatusResponseType) { request.setAttribute("SAMLResponse", encodedMessage); } else { _logger.warn("Invalid outbound message, not a RequestAbstractType or StatusResponseType"); throw new MessageEncodingException("Invalid outbound message"); } String relayState = messageContext.getRelayState(); if (checkRelayState(relayState)) { request.setAttribute("RelayState", relayState); } RequestDispatcher oDispatcher = request.getRequestDispatcher(_sTemplateLocation); oDispatcher.forward(request, response); } catch (UnsupportedEncodingException e) { _logger.warn("Could not encode message, charset: " + SAML2Constants.CHARSET, e); throw new MessageEncodingException("Could not encode message", e); } catch (ServletException e) { _logger.warn("Could not process forward to JSP due to Servlet Error", e); throw new MessageEncodingException("Could not process forward to JSP"); } catch (IOException e) { _logger.warn("Could not process forward to JSP due to I/O Error", e); throw new MessageEncodingException("Could not process forward to JSP"); } }
From source file:Index.RegisterUserServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . ja v a2 s . co 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 errorMessage; if (request.getParameter("user") != null && request.getParameter("password") != null && request.getParameter("email") != null && request.getParameter("passwordConfirmation") != null && request.getParameter("name") != null && request.getParameter("address") != null && request.getParameter("lastName") != null && request.getParameter("dateBorn") != null) { String user = request.getParameter("user"); String password = request.getParameter("password"); String passwordConfirmation = request.getParameter("passwordConfirmation"); String email = request.getParameter("email"); String name = request.getParameter("name"); String address = request.getParameter("address"); String lastName = request.getParameter("lastName"); String dateBorn = request.getParameter("dateBorn"); if (user.equalsIgnoreCase("") || password.equalsIgnoreCase("") || passwordConfirmation.equalsIgnoreCase("") || email.equalsIgnoreCase("") || name.equalsIgnoreCase("")) { errorMessage = "Ingrese todos los datos."; request.setAttribute("error", errorMessage); request.setAttribute("funcionalidad", "Registro"); request.getRequestDispatcher("/Login.jsp").forward(request, response); } else { if (password.equals(passwordConfirmation)) { QuickOrderWebService webService = new QuickOrderWebService(); ControllerInterface port = webService.getQuickOrderWebServicePort(); webservice.Cliente listCli = port.infoCliente(user); if (listCli != null && listCli.getApellido() != null) { errorMessage = "Ya existe un usuario con ese nickname"; request.setAttribute("error", errorMessage); request.setAttribute("funcionalidad", "Registro"); request.getRequestDispatcher("/Login.jsp").forward(request, response); } else { webservice.Cliente usr = new webservice.Cliente(); usr.setNickname(user); usr.setNombre(name); usr.setEmail(email); usr.setDireccion(address); usr.setImagen(user + ".jpg"); usr.setApellido(lastName); //PORCEDIMIENTO PARA ENCRIPTAR LA CLAVE INGRESADA CUANDO INICIA SESIN UN USUARIO. String encriptMD5 = DigestUtils.md5Hex(password); password = "md5:" + encriptMD5; usr.setPassword(password); Date dt; try { dt = new Date(dateBorn); } catch (Exception ex) { dt = Date.from(Instant.now()); } GregorianCalendar c = new GregorianCalendar(); c.setTime(dt); XMLGregorianCalendar date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); usr.setFechaNac(date2); String result = port.registrarCliente(usr); if (result.equals("")) { request.setAttribute("error", null); request.setAttribute("funcionalidad", "Imagen"); request.getSession().setAttribute("userName", user); } else { request.setAttribute("error", "Surgio un error al registrar el cliente"); request.setAttribute("funcionalidad", "Registro"); } request.getRequestDispatcher("/Login.jsp").forward(request, response); } } else { errorMessage = "Las contraseas no cohinciden"; request.setAttribute("error", errorMessage); request.setAttribute("funcionalidad", "Registro"); request.getRequestDispatcher("/Login.jsp").forward(request, response); } } } else { errorMessage = "Error al realizar el registro."; request.setAttribute("error", errorMessage); request.setAttribute("funcionalidad", "Registro"); request.getRequestDispatcher("/Login.jsp").forward(request, response); } } catch (Exception ex) { out.print("Error en proceso de registro: " + ex.getMessage()); } finally { out.close(); } }