本文整理汇总了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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
}