List of usage examples for javax.servlet.http HttpServletRequest getRequestDispatcher
public RequestDispatcher getRequestDispatcher(String path);
From source file:controller.uploadTeste.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w ww. j ava2s . 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 idLocal = (String) request.getParameter("idLocal"); String name = ""; //process only if its multipart content if (ServletFileUpload.isMultipartContent(request)) { try { List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); for (FileItem item : multiparts) { if (!item.isFormField()) { name = new File(item.getName()).getName(); // item.write( new File(UPLOAD_DIRECTORY + File.separator + name)); item.write(new File(AbsolutePath + File.separator + name)); } } //File uploaded successfully request.setAttribute("message", "File Uploaded Successfully"); } catch (Exception ex) { request.setAttribute("message", "File Upload Failed due to " + ex); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } request.getRequestDispatcher("/novoLocalTeste.jsp?nomeArquivo=" + name).forward(request, response); }
From source file:org.deegree.test.gui.StressTestController.java
/** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) *//*from www . j ava2 s . c o m*/ @Override @SuppressWarnings("unchecked") protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String action = request.getParameter("action"); String step1 = request.getParameter("step1"); String step2 = request.getParameter("step2"); String step3 = request.getParameter("step3"); String imageSource = request.getParameter("imgsrc"); String bigimg = request.getParameter("bigimg"); String shot = request.getParameter("shot"); String bigshot = request.getParameter("bigshot"); if (action != null && action.equalsIgnoreCase("status")) { String state = (String) request.getSession().getAttribute("applicationState"); if (state != null && state.equalsIgnoreCase("wait")) { RequestDispatcher dispatcher = request.getRequestDispatcher("/status.jsp"); HttpSession session = request.getSession(); String appState = (String) session.getAttribute("applicationState"); request.setAttribute("applicationState", appState); if (appState.equals("wait")) { String operation = (String) session.getAttribute("operationInProgress"); request.setAttribute("opeartionInProgress", operation); } List<TestResultData> partialRes = test.getResultData(); request.setAttribute("partialResults", partialRes); request.setAttribute("threads", threads); request.setAttribute("requests", requests); dispatcher.forward(request, response); } else if (state != null && state.equalsIgnoreCase("ready")) { RequestDispatcher dispatcher = request.getRequestDispatcher("/status.jsp"); HttpSession session = request.getSession(); request.setAttribute("applicationState", "ready"); resultData = (List<TestResultData>) session.getAttribute("resultData"); request.setAttribute("resultData", resultData); imgLinks = (List<String>) session.getAttribute("imgLinks"); request.setAttribute("imgLinks", imgLinks); showImg = (Boolean) session.getAttribute("showImage"); request.setAttribute("showImage", showImg); request.setAttribute("threads", threads); request.setAttribute("requests", requests); dispatcher.forward(request, response); } else { RequestDispatcher dispatcher = request.getRequestDispatcher("/status.jsp"); request.setAttribute("applicationState", "welcome"); dispatcher.forward(request, response); } } else if (action != null && action.equalsIgnoreCase("wpvs")) { RequestDispatcher dispatcher = request.getRequestDispatcher("/wpvs.jsp"); dispatcher.forward(request, response); } else if (action != null && action.equalsIgnoreCase("wms")) { RequestDispatcher dispatcher = request.getRequestDispatcher("/wms.jsp"); dispatcher.forward(request, response); } else if (step1 != null) { doStep1(request, response); } else if (step2 != null) { doStep2(request, response); } else if (step3 != null) { doStep3(request, response); } else if (imageSource != null) { drawDiagram(response, 400, 300); } else if (bigimg != null) { drawDiagram(response, 1000, 750); } else if (shot != null) { renderResizedImage(response, shot, 200, 150); } else if (bigshot != null) { renderImage(response, bigshot); } }
From source file:TripServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w . ja va 2s.c o m*/ DataClass.checkSession(request, response); //processRequest(request, response); // gohome(request, response); String goflag = request.getParameter("goflag"); if (goflag.equals("today")) { filterTrips(new Date()); request.setAttribute("trips", filterdtrips); } else if (goflag.equals("lastweek")) { filterTrips(getLastWeek()); request.setAttribute("trips", filterdtrips); } else if (goflag.equals("lastmonth")) { filterTrips(getLastMonth()); request.setAttribute("trips", filterdtrips); } else if (goflag.equals("lastyear")) { filterTrips(getLastYear()); request.setAttribute("trips", filterdtrips); } else if (goflag.equals("all")) { request.setAttribute("trips", alltrips); } else { gohome(request, response); } request.getRequestDispatcher("trips.jsp").forward(request, response);//show only } catch (Exception ex) { Logger.getLogger(TripServlet.class.getName()).log(Level.SEVERE, null, ex); gohome(request, response); } }
From source file:de.dentrassi.pm.storage.web.channel.ChannelController.java
@Secured(false) @RequestMapping(value = "/channel/{channelId}/view", method = RequestMethod.GET) @HttpConstraint(PERMIT)/*from w w w. j a va 2 s .c om*/ public ModelAndView view(@PathVariable("channelId") final String channelId, final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { final Channel channel = this.service.getChannelByAlias(channelId); if (channel != null) { return new ModelAndView(String.format("redirect:/channel/%s/view", channel.getId())); } else { request.getRequestDispatcher("tree").forward(request, response); return null; } }
From source file:com.lrodriguez.SVNBrowser.java
private void doSvnDateQuery(HttpServletRequest request, HttpServletResponse response, Date startDate, Date endDate) throws ServletException, IOException { logDebug("dispatching Date SVN query request"); List entriesList = getUniqueEntries(request, startDate, endDate);//get all files in date range if (request.getAttribute(ERROR) != null) { request.getRequestDispatcher(INDEX_JSP).forward(request, response); return;// ww w . j a v a 2 s . c o m } sortAndFilterSvnQuery(request, response, entriesList); return; }
From source file:com.vmware.bdd.rest.RestResource.java
@RequestMapping(value = "/cluster/{clusterName}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json") public void updateCluster(@PathVariable("clusterName") String clusterName, @RequestBody(required = false) ClusterCreate clusterUpdate, @RequestParam(value = "state", required = false) String state, @RequestParam(value = "force", required = false, defaultValue = "false") Boolean force, @RequestParam(value = "ignorewarning", required = false, defaultValue = "false") boolean ignoreWarning, @RequestParam(value = "append", required = false, defaultValue = "false") boolean append, HttpServletRequest request, HttpServletResponse response) throws Exception { if (state != null) { // forward request to startStop`() for backward compatibility request.getRequestDispatcher(clusterName + "/action").forward(request, response); response.setStatus(HttpStatus.ACCEPTED.value()); return;//from w w w . ja v a 2 s .co m } verifyInitialized(); clusterName = CommonUtil.decode(clusterName); if (CommonUtil.isBlank(clusterName) || !CommonUtil.validateResourceName(clusterName)) { throw BddException.INVALID_PARAMETER("cluster name", clusterName); } clusterMgr.updateCluster(clusterUpdate, ignoreWarning, append); response.setStatus(HttpStatus.OK.value()); }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (logger.isMdwDebugEnabled()) { logger.mdwDebug("SOAP Listener GET Request:\n" + request.getRequestURI() + (request.getQueryString() == null ? "" : ("?" + request.getQueryString()))); }/*from w w w .j av a 2 s .c om*/ if (request.getServletPath().endsWith(RPC_SERVICE_PATH) || RPC_SERVICE_PATH.equals(request.getPathInfo())) { Asset rpcWsdlAsset = AssetCache.getAsset(Package.MDW + "/MdwRpcWebService.wsdl", Asset.WSDL); response.setContentType("text/xml"); response.getWriter().print(substituteRuntimeWsdl(rpcWsdlAsset.getStringContent())); } else if (request.getPathInfo() == null || request.getPathInfo().equalsIgnoreCase("mdw.wsdl")) { // forward to general wsdl RequestDispatcher requestDispatcher = request.getRequestDispatcher("/mdw.wsdl"); requestDispatcher.forward(request, response); } else if (request.getPathInfo().toUpperCase().endsWith(Asset.WSDL)) { String wsdlAsset = request.getPathInfo().substring(1); Asset asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); if (asset == null) { // try trimming file extension wsdlAsset = wsdlAsset.substring(0, wsdlAsset.length() - 5); asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); } if (asset == null) { // try with lowercase extension wsdlAsset = wsdlAsset + ".wsdl"; asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); } if (asset == null) { String message = "No WSDL resource found: " + request.getPathInfo().substring(1); logger.severe(message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.getWriter().print(message); } else { response.setContentType("text/xml"); response.getWriter().print(substituteRuntimeWsdl(asset.getStringContent())); } } else { ServletException ex = new ServletException( "HTTP GET not supported for URL: " + request.getRequestURL()); logger.severeException(ex.getMessage(), ex); throw ex; } }
From source file:com.lrodriguez.SVNBrowser.java
private void doSortNoEntries(HttpServletRequest request, HttpServletResponse response, HttpSession session, Date startDate, Date endDate, Comparator comparator) throws ServletException, IOException { logDebug("dispatching Default request"); List uniqueEntries = getUniqueEntries(request, startDate, endDate); if (request.getAttribute(ERROR) != null) { request.getRequestDispatcher(INDEX_JSP).forward(request, response); return;//from www. jav a 2 s. c o m } Collections.sort(uniqueEntries, comparator); session.setAttribute(UNIQUE_ENTRIES, uniqueEntries); request.getRequestDispatcher(INDEX_JSP).forward(request, response); return; }
From source file:com.alfaariss.oa.profile.aselect.processor.handler.BrowserHandler.java
private void forwardToAutoRedirect(HttpServletRequest oServletRequest, HttpServletResponse oServletResponse, String sRedirect, IRequestor oRequestor) throws ASelectException { try {//from ww w .j av a2 s . c o m oServletRequest.setAttribute("redirect", sRedirect); if (oRequestor != null) {//Add requestor object as attribute oServletRequest.setAttribute(IRequestor.REQUESTOR_ATTRIBUTE_NAME, oRequestor); } oServletRequest.setAttribute(Server.SERVER_ATTRIBUTE_NAME, Engine.getInstance().getServer()); RequestDispatcher oDispatcher = oServletRequest.getRequestDispatcher(_sRedirectJspPath); if (oDispatcher != null) oDispatcher.forward(oServletRequest, oServletResponse); } catch (Exception e) { _logger.fatal("Internal error during forward to auto redirect page", e); throw new ASelectException(ASelectErrors.ERROR_ASELECT_INTERNAL_ERROR); } }
From source file:cn.itcast.bbs.controller.BbsServlet.java
private void editTopic(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try {/*from w w w . ja va 2 s. c o m*/ Topic topic = new Topic(); Enumeration<String> enums = request.getParameterNames(); while (enums.hasMoreElements()) { String key = enums.nextElement(); if (key.equals("method") || key.equals("typeId")) { continue; } String[] value = request.getParameterValues(key); BeanUtils.setProperty(topic, key, value); } service.updateTopic(topic); int typeId = Integer.parseInt(request.getParameter("typeId")); response.sendRedirect(request.getContextPath() + "/BbsServlet?method=showAllTopic&typeId=" + typeId); } catch (Exception e) { e.printStackTrace(); request.setAttribute("message", ""); request.getRequestDispatcher("/WEB-INF/bbs/message.jsp").forward(request, response); } }