当前位置: 首页>>代码示例>>Java>>正文


Java RequestDispatcher类代码示例

本文整理汇总了Java中javax.servlet.RequestDispatcher的典型用法代码示例。如果您正苦于以下问题:Java RequestDispatcher类的具体用法?Java RequestDispatcher怎么用?Java RequestDispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


RequestDispatcher类属于javax.servlet包,在下文中一共展示了RequestDispatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGet

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String destino;
    request.setCharacterEncoding("UTF-8");
    HttpSession sessao = request.getSession();
    if (sessao.getAttribute("usuario") != null) {
        request.setAttribute("usuario", sessao.getAttribute("usuario"));
        // Remove o atributo da sessao para usuario nao ficar preso na tela de resultados           

        destino = "alterarUsuario.jsp";
    } else {
        destino = "alterarUsuario.jsp";
    }

    RequestDispatcher dispatcher = request.getRequestDispatcher(destino);
    dispatcher.forward(request, response);

}
 
开发者ID:Dinossaura,项目名称:LojaDeInstrumentosMusicais,代码行数:20,代码来源:EditarUsuarioServlet.java

示例2: doGet

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    
    List<Cliente> clientes = new ArrayList<>();
    ClienteDAO cd = new ClienteDAO();
    try {
        //clientes = cd.listarCliente("");
    } catch (Exception ex) {
        Logger.getLogger(ConsultarClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
    
    request.setAttribute("listaClientes", clientes);
    RequestDispatcher dispatcher = request.getRequestDispatcher("consultarCliente.jsp");
dispatcher.forward(request, response);
}
 
开发者ID:Dinossaura,项目名称:LojaDeInstrumentosMusicais,代码行数:17,代码来源:ConsultarClienteServlet.java

示例3: getHtmlServiceProvider

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * Return the catalog singleton as HTML
 *
 * Forwards to serviceprovidercatalog_html.jsp to build the html
 *
 * @param serviceProviderId
 */
@GET
@Path("{someId}")
@Produces(MediaType.TEXT_HTML)
public void getHtmlServiceProvider(@PathParam("someId") final String someId)
{
    ServiceProviderCatalog catalog = ServiceProviderCatalogSingleton.getServiceProviderCatalog(httpServletRequest);

    if (catalog !=null )
    {
        httpServletRequest.setAttribute("catalog",catalog);
        // Start of user code getHtmlServiceProvider_setAttributes
        // End of user code

        RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/se/ericsson/cf/scott/sandbox/serviceprovidercatalog.jsp");
        try {
            rd.forward(httpServletRequest, httpServletResponse);
        } catch (Exception e) {
            e.printStackTrace();
            throw new WebApplicationException(e);
        }
    }
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:30,代码来源:ServiceProviderCatalogService.java

示例4: doPost

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	try{
		int appointmentId = Integer.valueOf(request.getParameter("appointmentId"));
		String by = (String)request.getParameter("by");
		int status = new DatabaseHelper().closeAppointment(appointmentId, by);
		if (status > 0) {
			// successfully inserted
			RequestDispatcher rs;
			rs = request.getRequestDispatcher((String)request.getParameter("requestDispatcher"));
			request.setAttribute("appointmentId", appointmentId);
			rs.forward(request, response);
		} else {
			// redirect to login
			redirectToLogin(request, response);
		}
	}catch(Exception e){
		e.printStackTrace();
		// redirect to login
		redirectToLogin(request, response);
	}
}
 
开发者ID:jainkuniya,项目名称:central-medic-center,代码行数:25,代码来源:CloseAppointment.java

示例5: doPost

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	// TODO Auto-generated method stub
	ReadQuery rq = new ReadQuery("faculty");
	String affectedTable = rq.doRead("faculty");
	String table = rq.createHTMLTable();
	
	request.setAttribute("table", table);
	request.setAttribute("affectedTable", affectedTable);
	String url = "/table.jsp";
	
	if(request.getAttribute("message") != null) {
		request.setAttribute("message", (String) request.getAttribute("message"));
	}
	
	RequestDispatcher dispatcher = request.getRequestDispatcher(url);
	dispatcher.forward(request, response);
}
 
开发者ID:theBusBoy,项目名称:ChemistryAdministrativePortal,代码行数:21,代码来源:FacultyServlet.java

示例6: handleMissingResource

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
private void handleMissingResource(HttpServletRequest request, HttpServletResponse response, String jspUri)
		throws ServletException, IOException {

	String includeRequestUri = (String) request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);

	if (includeRequestUri != null) {
		// This file was included. Throw an exception as
		// a response.sendError() will be ignored
		String msg = Localizer.getMessage("jsp.error.file.not.found", jspUri);
		// Strictly, filtering this is an application
		// responsibility but just in case...
		throw new ServletException(SecurityUtil.filter(msg));
	} else {
		try {
			response.sendError(HttpServletResponse.SC_NOT_FOUND, request.getRequestURI());
		} catch (IllegalStateException ise) {
			log.error(Localizer.getMessage("jsp.error.file.not.found", jspUri));
		}
	}
	return;
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:22,代码来源:JspServlet.java

示例7: getPath

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
private String getPath(final HttpServletRequest request) {
    String servletPath;
    String pathInfo;

    if (request.getDispatcherType() == DispatcherType.INCLUDE && request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
        pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
        servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
    } else {
        pathInfo = request.getPathInfo();
        servletPath = request.getServletPath();
    }
    String result = pathInfo;
    if (result == null) {
        result = servletPath;
    } else if(resolveAgainstContextRoot) {
        result = servletPath + CanonicalPathUtils.canonicalize(pathInfo);
    } else {
        result = CanonicalPathUtils.canonicalize(result);
    }
    if ((result == null) || (result.equals(""))) {
        result = "/";
    }
    return result;

}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:DefaultServlet.java

示例8: include

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * Perform a RequestDispatcher.include() operation, with optional flushing
 * of the response beforehand.
 *
 * @param request The servlet request we are processing
 * @param response The servlet response we are processing
 * @param relativePath The relative path of the resource to be included
 * @param out The Writer to whom we are currently writing
 * @param flush Should we flush before the include is processed?
 *
 * @exception IOException if thrown by the included servlet
 * @exception ServletException if thrown by the included servlet
 */
public static void include(ServletRequest request,
                           ServletResponse response,
                           String relativePath,
                           JspWriter out,
                           boolean flush)
    throws IOException, ServletException {

    if (flush && !(out instanceof BodyContent))
        out.flush();

    // FIXME - It is tempting to use request.getRequestDispatcher() to
    // resolve a relative path directly, but Catalina currently does not
    // take into account whether the caller is inside a RequestDispatcher
    // include or not.  Whether Catalina *should* take that into account
    // is a spec issue currently under review.  In the mean time,
    // replicate Jasper's previous behavior

    String resourcePath = getContextRelativePath(request, relativePath);
    RequestDispatcher rd = request.getRequestDispatcher(resourcePath);

    rd.include(request,
               new ServletResponseWrapperInclude(response, out));

}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:38,代码来源:JspRuntimeLibrary.java

示例9: testDoFilter_saml

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
@Test
public void testDoFilter_saml() throws Exception {
    doReturn(true).when(closedMplFilter).isSAMLAuthentication();

    // given
    RequestDispatcher dispatcherMock = mock(RequestDispatcher.class);
    ServletContext mockServletContext = mock(ServletContext.class);
    doReturn(mockServletContext).when(requestMock).getServletContext();
    doReturn(dispatcherMock).when(mockServletContext).getRequestDispatcher(
            any(String.class));
    doReturn(true).when(closedMplFilter).isSAMLAuthentication();
    doReturn("/portal/*").when(requestMock).getServletPath();
    doReturn("mpid").when(sessionMock).getAttribute(
            Constants.REQ_PARAM_MARKETPLACE_ID);
    doReturn(getConfiguration(true, true, "testOrg")).when(closedMplFilter)
            .getConfig("mpid");
    doReturn(getUserDetails("anotherOrg")).when(sessionMock).getAttribute(
            Constants.SESS_ATTR_USER);

    // when
    closedMplFilter.doFilter(requestMock, responseMock, chainMock);

    // then
    verify(dispatcherMock, times(1)).forward(requestMock, responseMock);

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:27,代码来源:ClosedMarketplaceFilterTest.java

示例10: invoke

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * Select the appropriate child Wrapper to process this request,
 * based on the specified request URI.  If no matching Wrapper can
 * be found, return an appropriate HTTP error.
 *
 * @param request Request to be processed
 * @param response Response to be produced
 *
 * @exception IOException if an input/output error occurred
 * @exception ServletException if a servlet error occurred
 */
@Override
public final void invoke(Request request, Response response)
    throws IOException, ServletException {

    // Disallow any direct access to resources under WEB-INF or META-INF
    MessageBytes requestPathMB = request.getRequestPathMB();
    if ((requestPathMB.startsWithIgnoreCase("/META-INF/", 0))
            || (requestPathMB.equalsIgnoreCase("/META-INF"))
            || (requestPathMB.startsWithIgnoreCase("/WEB-INF/", 0))
            || (requestPathMB.equalsIgnoreCase("/WEB-INF"))) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // Select the Wrapper to be used for this Request
    Wrapper wrapper = request.getWrapper();
    if (wrapper == null || wrapper.isUnavailable()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // Acknowledge the request
    try {
        response.sendAcknowledgement();
    } catch (IOException ioe) {
        container.getLogger().error(sm.getString(
                "standardContextValve.acknowledgeException"), ioe);
        request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, ioe);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    }
    
    if (request.isAsyncSupported()) {
        request.setAsyncSupported(wrapper.getPipeline().isAsyncSupported());
    }
    wrapper.getPipeline().getFirst().invoke(request, response);
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:49,代码来源:StandardContextValve.java

示例11: notifyAttributeRemoved

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * Notify interested listeners that attribute has been removed.
 */
private void notifyAttributeRemoved(String name, Object value) {
    Object listeners[] = context.getApplicationEventListeners();
    if ((listeners == null) || (listeners.length == 0)) {
        return;
    }
    ServletRequestAttributeEvent event =
      new ServletRequestAttributeEvent(context.getServletContext(),
                                       getRequest(), name, value);
    for (int i = 0; i < listeners.length; i++) {
        if (!(listeners[i] instanceof ServletRequestAttributeListener)) {
            continue;
        }
        ServletRequestAttributeListener listener =
            (ServletRequestAttributeListener) listeners[i];
        try {
            listener.attributeRemoved(event);
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            context.getLogger().error(sm.getString("coyoteRequest.attributeEvent"), t);
            // Error valve will pick this exception up and display it to user
            attributes.put(RequestDispatcher.ERROR_EXCEPTION, t);
        }
    }
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:28,代码来源:Request.java

示例12: doGet

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
	try {
		HttpSession session = request.getSession();
		int adminId = (int) session.getAttribute("UserID");
		// get admin details
		DatabaseHelper databaseHelper = new DatabaseHelper();
		Staff admin = databaseHelper.getStaff(adminId);
		if (admin == null ) {
			// redirect to login
			redirectToLogin(request, response);
			return;
		}
		// redirect to admin dashboard
		RequestDispatcher rs = request.getRequestDispatcher("editAdminProfile.jsp");
		request.setAttribute("admin", admin);
		rs.forward(request, response);
		return;
	} catch (Exception e) {
		// redirect to login
		redirectToLogin(request, response);
	}
}
 
开发者ID:jainkuniya,项目名称:central-medic-center,代码行数:27,代码来源:UpdateAdminProfile.java

示例13: editar

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
* Edita um álbum no banco de dados
* @param request requisição
* @param response resposta
* @throws ServletException se ocorre um erro no Servlet
* @throws IOException se ocorre um erro de entrada e saída
*/
private void editar(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
        Integer id = Integer.parseInt(request.getParameter("idalbum"));
        
        AlbumBO bo = new AlbumBO();
        Album album = bo.selecionar(id);
        
        Usuario usuario = getUsuario(request);
        request.setAttribute("usuario", usuario);
        
        request.setAttribute("album", album);
        request.setAttribute("mensagem", "Registro Selecionado com sucesso!");
    } catch (Exception ex) {
        request.setAttribute("erro", ex.getMessage());
    }
    
    RequestDispatcher rd = request.getRequestDispatcher("paginas/galeria/cadastro_albuns.jsp");
    rd.forward(request, response);
}
 
开发者ID:Ronneesley,项目名称:redesocial,代码行数:27,代码来源:AlbumControle.java

示例14: doGet

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request,
 HttpServletResponse response) throws ServletException, IOException {

	Connection conn = MyUtils.getStoredConnection(request);

    String errorString = null;
    List<Product> list = null;
    try {
    	if (conn == null) // if conn was not stored
    		conn = ConnectionUtils.getConnection();
        list = DBUtils.queryProduct(conn);
    } catch (Exception e) {
        e.printStackTrace();
        errorString = e.getMessage();
    }

    // store info in request attribute, before forward to views
    request.setAttribute("errorString", errorString);
    request.setAttribute("productList", list);

    // forward to /WEB-INF/views/productListView.jsp
    RequestDispatcher dispatcher = request.getServletContext()
            .getRequestDispatcher("/WEB-INF/views/productListView.jsp");
    dispatcher.forward(request, response);
}
 
开发者ID:biblelamp,项目名称:JavaEE,代码行数:27,代码来源:ProductListServlet.java

示例15: doPost

import javax.servlet.RequestDispatcher; //导入依赖的package包/类
/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	try {			
		// get doctor lab report id
		int labReportId = Integer.parseInt((String)request.getParameter("labId"));
		DatabaseHelper databaseHelper = new DatabaseHelper();
		int status = databaseHelper.updateLabReport(labReportId, (String)request.getParameter("result"), 
				Integer.parseInt((String)request.getParameter("itemId")));
		if (status<=0) {
			//error
			// redirect to login
			redirectToLogin(request, response);
			return;
		}
		// redirect to lab person dashboard
		RequestDispatcher rs = request.getRequestDispatcher("labPerson");
		rs.forward(request, response);
		return;
	} catch (Exception e) {
		// redirect to login
		redirectToLogin(request, response);
	}
}
 
开发者ID:jainkuniya,项目名称:central-medic-center,代码行数:26,代码来源:SubmitLabReport.java


注:本文中的javax.servlet.RequestDispatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。