List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:com.alfaariss.oa.authentication.remote.saml2.selector.DefaultSelector.java
private void forwardUser(HttpServletRequest oRequest, HttpServletResponse oResponse, ISession oSession, List<SAML2IDP> listIDPs, String sMethodName, List<Warnings> oWarnings) throws OAException { try {/*from w ww . j a va 2 s.co m*/ //set request attributes oRequest.setAttribute(ISession.ID_NAME, oSession.getId()); oRequest.setAttribute(ISession.LOCALE_NAME, oSession.getLocale()); oRequest.setAttribute(REQUEST_PARAM_IDPS, listIDPs); if (oWarnings != null) oRequest.setAttribute(DetailedUserException.DETAILS_NAME, oWarnings); oRequest.setAttribute(IWebAuthenticationMethod.AUTHN_METHOD_ATTRIBUTE_NAME, sMethodName); oRequest.setAttribute(Server.SERVER_ATTRIBUTE_NAME, Engine.getInstance().getServer()); RequestDispatcher oDispatcher = oRequest.getRequestDispatcher(_sTemplatePath); if (oDispatcher == null) { _logger.warn("There is no request dispatcher supported with name: " + _sTemplatePath); throw new OAException(SystemErrors.ERROR_INTERNAL); } _logger.debug("Forward user to: " + _sTemplatePath); oDispatcher.forward(oRequest, oResponse); } catch (OAException e) { throw e; } catch (Exception e) { _logger.fatal("Internal error during forward", e); throw new OAException(SystemErrors.ERROR_INTERNAL); } }
From source file:com.tenduke.example.scribeoauth.oauth10a.OAuth10aLoginServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * * @param request servlet request//from w w w . j ava 2 s . c o 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(); // OAuthService service = new ServiceBuilder().provider(provider).apiKey(provider.getApiKey()) .apiSecret(provider.getApiSecret()).callback(provider.getCallbackUrl()).build(); // try { // Token requestToken = service.getRequestToken(); // String authzUrl = service.getAuthorizationUrl(requestToken); response.sendRedirect(authzUrl); // storeRequestToken(requestToken); } catch (Throwable t) { // request.setAttribute("exception", t); request.getRequestDispatcher("/oauthError.jsp").forward(request, response); } }
From source file:com.jyhon.servlet.user.SignInServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //?/*from w ww . j a va 2 s . co m*/ request.setCharacterEncoding("UTF-8"); //?IOC? UserEntityService userEntityService = new UserEntityServiceImpl(); //? String pathTemp = InitFileFolder(); List<FileItem> items = getFileItems(request, pathTemp); UserEntity userEntity = getUserEntity(items); //??? VerifyUtil verifyUtil = new VerifyUtil(); if (verifySignInData(request, response, userEntity, verifyUtil)) return; //?? Integer dbResult = userEntityService.addEntity(userEntity); //?? if (dbResult <= 0) { request.setAttribute("ErrorMessage", "DataBase Insert fail!"); request.getRequestDispatcher("register.jsp").forward(request, response); return; } //? request.setAttribute("ReminderMessage", "Register Success please login"); request.getRequestDispatcher("login.jsp").forward(request, response); }
From source file:com.mycompany.mytubeaws.ListServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/* w w w . j a 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 doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ArrayList<String> nameList = new ArrayList<>(); ArrayList<String> sizeList = new ArrayList<>(); ArrayList<String> dateList = new ArrayList<>(); ObjectListing objects = s3.listObjects(bucketName); do { for (S3ObjectSummary objectSummary : objects.getObjectSummaries()) { nameList.add(objectSummary.getKey()); sizeList.add(Long.toString(objectSummary.getSize())); dateList.add(StringUtils.fromDate(objectSummary.getLastModified())); } objects = s3.listNextBatchOfObjects(objects); } while (objects.isTruncated()); request.setAttribute("nameList", nameList); request.setAttribute("sizeList", sizeList); request.setAttribute("dateList", dateList); request.getRequestDispatcher("/UploadResult.jsp").forward(request, response); }
From source file:org.overlord.sramp.server.servlets.MavenRepositoryServlet.java
/** * List items response./*from w ww.j a va2 s .c o m*/ * * @param req * the req * @param resp * the resp * @param url * the url * @throws ServletException * the servlet exception * @throws IOException * Signals that an I/O exception has occurred. */ private void listItemsResponse(HttpServletRequest req, HttpServletResponse resp, String url) throws ServletException, IOException { if (!url.endsWith("/")) { //$NON-NLS-1$ url = url + "/"; //$NON-NLS-1$ } try { // Gets all the items from the maven url Set<String> items = service.getItems(url); // If there are items or the request is the root maven folder if ((items != null && items.size() > 0) || (url.equals("/") || url.equals(""))) { //$NON-NLS-1$ //$NON-NLS-2$ // Dispatch the request to the JSP that would display the items RequestDispatcher dispatcher = req.getRequestDispatcher(JSP_LOCATION_LIST_DIR); if (StringUtils.isNotBlank(url) && !url.equals("/")) { //$NON-NLS-1$ String[] urlTokens = url.split("/"); //$NON-NLS-1$ String parentPath = ""; //$NON-NLS-1$ if (urlTokens.length > 1) { for (int i = 0; i < urlTokens.length - 1; i++) { parentPath += urlTokens[i] + "/"; //$NON-NLS-1$ } } parentPath = "/" + parentPath; //$NON-NLS-1$ req.setAttribute("parentPath", parentPath); //$NON-NLS-1$ } else { url = ""; //$NON-NLS-1$ } req.setAttribute("relativePath", url); //$NON-NLS-1$ req.setAttribute("items", items); //$NON-NLS-1$ dispatcher.forward(req, resp); } else { resp.setStatus(HttpStatus.SC_NOT_FOUND); } } catch (MavenRepositoryException e) { resp.sendError(HttpStatus.SC_NOT_FOUND, e.getMessage()); } }
From source file:ie.wombat.rt.fireeagle.CookieConsumer.java
/** * Handle an exception that occurred while processing an HTTP request. * Depending on the exception, either send a response, redirect the client * or propagate an exception.// ww w . ja v a2s. co m */ public static void handleException(Exception e, HttpServletRequest request, HttpServletResponse response, OAuthConsumer consumer) throws IOException, ServletException { if (e instanceof RedirectException) { RedirectException redirect = (RedirectException) e; String targetURL = redirect.getTargetURL(); if (targetURL != null) { response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", targetURL); } } else if (e instanceof OAuthProblemException) { OAuthProblemException p = (OAuthProblemException) e; String problem = p.getProblem(); if (consumer != null && RECOVERABLE_PROBLEMS.contains(problem)) { try { CookieMap cookies = new CookieMap(request, response); OAuthAccessor accessor = newAccessor(consumer, cookies); getAccessToken(request, cookies, accessor); // getAccessToken(request, consumer, // new CookieMap(request, response)); } catch (Exception e2) { handleException(e2, request, response, null); } } else { try { StringWriter s = new StringWriter(); PrintWriter pw = new PrintWriter(s); e.printStackTrace(pw); pw.flush(); p.setParameter("stack trace", s.toString()); } catch (Exception rats) { } response.setStatus(p.getHttpStatusCode()); response.resetBuffer(); request.setAttribute("OAuthProblemException", p); request.getRequestDispatcher // ("/OAuthProblemException.jsp").forward(request, response); } } else if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ServletException) { throw (ServletException) e; } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ServletException(e); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.edit.RefactorRetryController.java
public void doGet(HttpServletRequest request, HttpServletResponse response) { if (!isAuthorizedToDisplayPage(request, response, SimplePermission.EDIT_ONTOLOGY.ACTION)) { return;/*w w w. j a va2 s .c om*/ } //create an EditProcessObject for this and put it in the session EditProcessObject epo = super.createEpo(request); VitroRequest vreq = new VitroRequest(request); String modeStr = request.getParameter("mode"); if (modeStr != null) { if (modeStr.equals("renameResource")) { doRenameResource(vreq, response, epo); } else if (modeStr.equals("movePropertyStatements")) { doMovePropertyStatements(vreq, response, epo); } else if (modeStr.equals("moveInstances")) { doMoveInstances(vreq, response, epo); } } RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); setRequestAttributes(request, epo); try { rd.forward(request, response); } catch (Exception e) { log.error(this.getClass().getName() + " could not forward to view."); log.error(e.getMessage()); log.error(e.getStackTrace()); } }
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void showReply(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/* w ww . j a va2s.com*/ int typeId = Integer.parseInt(request.getParameter("typeId")); int topicId = Integer.parseInt(request.getParameter("topicId")); List<Reply> replyList = service.findAllReply(topicId); Topic topic = service.findTopicById(topicId); request.setAttribute("typeId", typeId); request.setAttribute("replyList", replyList); request.setAttribute("topic", topic); request.getRequestDispatcher("/WEB-INF/bbs/listAllReply.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); request.setAttribute("message", "?"); request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response); } }
From source file:edu.cornell.mannlib.vitro.webapp.controller.OntologyController.java
private void doNotFound(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { VitroRequest vreq = new VitroRequest(req); ApplicationBean appBean = vreq.getAppBean(); //set title before we do the highlighting so we don't get markup in it. req.setAttribute("title", "not found"); res.setStatus(HttpServletResponse.SC_NOT_FOUND); String css = "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"" + appBean.getThemeDir() + "css/entity.css\"/>" + "<script language='JavaScript' type='text/javascript' src='js/toggle.js'></script>"; req.setAttribute("css", css); req.setAttribute("bodyJsp", "/" + Controllers.ENTITY_NOT_FOUND_JSP); RequestDispatcher rd = req.getRequestDispatcher(Controllers.BASIC_JSP); rd.forward(req, res);// www . jav a2s . c om }
From source file:com.maya.portAuthority.googleMaps.MapsService.java
/** * Web application to determine nearest bus stop from a source location for a given route# and * direction of transit.//w w w .j a v a 2 s.c om */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { //NearestStopLocator p = new NearestStopLocator(); //Inputs fom UI: String source = request.getParameter("source").replaceAll("\\s", "+"); String route = request.getParameter("route").trim(); String direction = request.getParameter("direction").trim(); try { Location c = NearestStopLocator.getSourceLocation(source); Stop stop = NearestStopLocator.process(c, route, direction); request.setAttribute("nearestStopName", stop.getStopName()); } catch (JSONException ex) { Logger.getLogger(MapsService.class.getName()).log(Level.SEVERE, null, ex); } catch (InvalidInputException ex) { Logger.getLogger(MapsService.class.getName()).log(Level.SEVERE, null, ex); } //direct to the results page RequestDispatcher view = request.getRequestDispatcher("result.jsp"); view.forward(request, response); }