List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void toeditTopicJsp(HttpServletRequest request, HttpServletResponse response) { try {//from w ww . j a v a 2 s . com int typeId = Integer.parseInt(request.getParameter("typeId")); int topicId = Integer.parseInt(request.getParameter("topicId")); Topic topic = service.findTopicById(topicId); request.setAttribute("typeId", typeId); request.setAttribute("topic", topic); request.getRequestDispatcher("/WEB-INF/bbs/editTopic.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); } }
From source file:controller.ViewEC.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from www . j a v a 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 { try { response.setContentType("text/html;charset=UTF-8"); int ecId = Integer.parseInt(request.getParameter("id")); String action = request.getParameter("action"); ExtenuatingCircumstance ec = new ExtenuatingCircumstanceDAO().retrieveECById(ecId); ArrayList<Evidence> evidences = new EvidenceDAO().retrieveEvidenceByEcId(ecId); request.setAttribute("ec", ec); request.setAttribute("evidences", evidences); request.setAttribute("role", request.getParameter("role")); if (StringUtils.equals(action, "edit")) { request.getRequestDispatcher("UpdateEC.jsp").forward(request, response); } else { request.getRequestDispatcher("ViewECDetail.jsp").forward(request, response); } } catch (SQLException ex) { Logger.getLogger(ViewEC.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.arcadian.loginservlet.StudentAssignmentServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { assignmentFoldetService = new AssignmentFolderService(); HttpSession session = request.getSession(); username = (String) session.getAttribute("username"); ArrayList<AssignmentNoticeBean> alstAssignmentNotice = assignmentFoldetService .fetchAssignmentNotice(username); request.setAttribute("alstAssignmentNotice", alstAssignmentNotice); RequestDispatcher dispatcher = request.getRequestDispatcher("dashboard/assignmentfolder.jsp"); dispatcher.forward(request, response); }/* w w w. j a v a 2 s .c o m*/ }
From source file:edu.lternet.pasta.portal.LogoutServlet.java
/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * //from ww w. j a va2 s .com * @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 */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession httpSession = request.getSession(); String uid = (String) httpSession.getAttribute("uid"); if (uid == null) { logger.error("User identifier \"uid\" is null\n"); httpSession.invalidate(); } else { TokenManager tokenManager = new TokenManager(); try { tokenManager.deleteToken(uid); } catch (Exception e) { handleDataPortalError(logger, e); } finally { httpSession.invalidate(); } } RequestDispatcher requestDispatcher = request.getRequestDispatcher("./home.jsp"); requestDispatcher.forward(request, response); }
From source file:com.centurylink.mdw.hub.servlet.RestServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { CodeTimer timer = new CodeTimer("RestServlet.doGet()", true); if (request.getPathInfo() == null) { // redirect to html documentation response.sendRedirect(ApplicationContext.getMdwHubUrl() + "/doc/webServices.html"); return;/*w w w . j a v a 2 s. co m*/ } else if (request.getPathInfo().startsWith("/SOAP")) { // forward to SOAP servlet RequestDispatcher requestDispatcher = request.getRequestDispatcher(request.getPathInfo()); requestDispatcher.forward(request, response); return; } else if (ApplicationContext.isDevelopment() && isFromLocalhost(request)) { // this is only allowed from localhost and in dev if ("/System/exit".equals(request.getPathInfo())) { response.setStatus(200); new Thread(new Runnable() { public void run() { System.exit(0); } }).start(); return; } } Map<String, String> metaInfo = buildMetaInfo(request); try { String responseString = handleRequest(request, response, metaInfo); String downloadFormat = metaInfo.get(Listener.METAINFO_DOWNLOAD_FORMAT); if (downloadFormat != null) { response.setContentType(Listener.CONTENT_TYPE_DOWNLOAD); String fileName = request.getPathInfo().substring(1).replace('/', '-') + "." + downloadFormat; response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\""); if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_JSON) || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_XML) || downloadFormat.equals(Listener.DOWNLOAD_FORMAT_TEXT)) { response.getOutputStream().write(responseString.getBytes()); } else if (downloadFormat.equals(Listener.DOWNLOAD_FORMAT_FILE)) { String f = metaInfo.get(Listener.METAINFO_DOWNLOAD_FILE); if (f == null) throw new ServiceException(ServiceException.INTERNAL_ERROR, "Missing meta"); File file = new File(f); if (!file.isFile()) throw new ServiceException(ServiceException.NOT_FOUND, "File not found: " + file.getAbsolutePath()); int max = PropertyManager.getIntegerProperty(PropertyNames.MAX_DOWNLOAD_BYTES, 104857600); if (file.length() > max) throw new ServiceException(ServiceException.NOT_ALLOWED, file.getAbsolutePath() + " exceeds max download size (" + max + "b )"); response.setHeader("Content-Disposition", "attachment;filename=\"" + file.getName() + "\""); try (InputStream in = new FileInputStream(file)) { int read = 0; byte[] bytes = new byte[8192]; while ((read = in.read(bytes)) != -1) response.getOutputStream().write(bytes, 0, read); } } else { // for binary content string response will have been Base64 encoded response.getOutputStream().write(Base64.decodeBase64(responseString.getBytes())); } } else { if ("/System/sysInfo".equals(request.getPathInfo()) && "application/json".equals(metaInfo.get(Listener.METAINFO_CONTENT_TYPE))) { responseString = WebAppContext.addContextInfo(responseString, request); } response.getOutputStream().write(responseString.getBytes()); } } catch (ServiceException ex) { logger.severeException(ex.getMessage(), ex); response.setStatus(ex.getCode()); response.getWriter().println(createErrorResponseMessage(request, metaInfo, ex)); } finally { timer.stopAndLogTiming(""); } }
From source file:cn.vlabs.umt.ui.servlet.AuthorizationCodeServlet.java
private void dealClientRedirectError(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.getRequestDispatcher("/oauth/redirecturlerror.jsp").forward(request, response); }
From source file:com.sbu.controller.Feed_Personal_Startup_View_Controller.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); Startup User = new Startup(); List<Member1> members = new ArrayList(); int counter = 1; HttpSession session = request.getSession(); User = (Startup) request.getSession().getAttribute("User"); //members= (ArrayList<Member1>) request.getSession().getAttribute("members"); members = memberService.getMemberByStartupId(User.getIdStartup()); session.setAttribute("SearchQueries", User); session.setAttribute("members", members); session.setAttribute("counter", counter); //request.getRequestDispatcher("EmployeeTest.jsp").forward(request, response); request.getRequestDispatcher("/Personal_Startup.jsp").forward(request, response); }
From source file:com.myhexin.filter.FileMultipartFilter.java
/** * /* w w w . ja v a 2s.c o m*/ */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { MultipartResolver multipartResolver = lookupMultipartResolver(request); HttpServletRequest processedRequest = request; if (multipartResolver.isMultipart(processedRequest)) { if (logger.isDebugEnabled()) { logger.debug("Resolving multipart request [" + processedRequest.getRequestURI() + "] with MultipartFilter"); } processedRequest = multipartResolver.resolveMultipart(processedRequest); if (XSSSecurityConfig.IS_CHECK_HEADER || XSSSecurityConfig.IS_CHECK_PARAMETER) { if (isIlleageXssParam((MultipartHttpServletRequest) processedRequest)) {//?? processedRequest.getRequestDispatcher(XSSSecurityConfig.XSS_ERROR_PAGE_PATH).forward(request, response); return; } } if (FILE_FILTER_ISOPEN) { if (isIllegalFileSuffix((MultipartHttpServletRequest) processedRequest)) {//?? processedRequest.getRequestDispatcher(XSSSecurityConfig.XSS_ERROR_PAGE_PATH).forward(request, response); return; } } } else { if (logger.isDebugEnabled()) { logger.debug("Request [" + processedRequest.getRequestURI() + "] is not a multipart request"); } } try { filterChain.doFilter(processedRequest, response); } finally { if (processedRequest instanceof MultipartHttpServletRequest) { multipartResolver.cleanupMultipart((MultipartHttpServletRequest) processedRequest); } } }
From source file:com.krawler.esp.servlets.ProfileImageServlet.java
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { // Get the absolute path of the image ServletContext sc = getServletContext(); String uri = req.getRequestURI(); String servletBase = req.getServletPath(); if (!StringUtil.isNullOrEmpty(req.getParameter("flag"))) { try {//from w ww . j av a 2 s . c om // TODO: Fix hardcoded url if (!StringUtil.isNullOrEmpty(req.getParameter("trackid"))) { String url = "/remoteapi.jsp?action=100&data={\"iscommit\":true}&trackid=" + req.getParameter("trackid"); RequestDispatcher rd = req.getRequestDispatcher(url); rd.include(req, resp); } String fileName = StorageHandler.GetProfileImgStorePath() + "blankImage.png"; File file = new File(fileName); if (file.exists()) { FileInputStream in = new FileInputStream(file); OutputStream out = resp.getOutputStream(); // Copy the contents of the file to the output stream byte[] buf = new byte[4096]; int count = 0; while ((count = in.read(buf)) >= 0) { out.write(buf, 0, count); } in.close(); out.close(); } } catch (Exception e) { logger.warn(e.getMessage(), e); } } else { boolean Companyflag = (req.getParameter("company") != null) ? true : false; String imagePath = defaultImgPath; String requestedFileName = ""; if (Companyflag) { imagePath = defaultCompanyImgPath; String companyId = null; try { companyId = sessionHandlerImpl.getCompanyid(req); } catch (Exception ee) { logger.warn(ee.getMessage(), ee); } if (StringUtil.isNullOrEmpty(companyId)) { String domain = URLUtil.getDomainName(req); if (!StringUtil.isNullOrEmpty(domain)) { //@@@ // companyId = sessionHandlerImpl.getCompanyid(domain); requestedFileName = "/original_" + companyId + ".png"; } else { requestedFileName = "logo.gif"; } } else { requestedFileName = "/" + companyId + ".png"; } } else { requestedFileName = uri.substring(uri.lastIndexOf(servletBase) + servletBase.length()); } String fileName = null; fileName = StorageHandler.GetProfileImgStorePath() + requestedFileName; // Get the MIME type of the image String mimeType = sc.getMimeType(fileName); if (mimeType == null) { sc.log("Could not get MIME type of " + fileName); resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } // Set content type resp.setContentType(mimeType); // Set content size File file = new File(fileName); if (!file.exists()) { if (fileName.contains("_100.")) { file = new File(fileName.replaceAll("_100.", ".")); } if (!file.exists()) { file = new File(sc.getRealPath(imagePath)); } } resp.setContentLength((int) file.length()); // Open the file and output streams FileInputStream in = new FileInputStream(file); OutputStream out = resp.getOutputStream(); // Copy the contents of the file to the output stream byte[] buf = new byte[4096]; int count = 0; while ((count = in.read(buf)) >= 0) { out.write(buf, 0, count); } in.close(); out.close(); } }
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void deleteType(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int typeId = Integer.parseInt(request.getParameter("typeId")); try {/*from w ww. j a v a2 s.c om*/ service.deleteType(typeId); response.sendRedirect(request.getContextPath()); } catch (Exception e) { e.printStackTrace(); request.setAttribute("message", "?"); request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response); } }