本文整理了Java中javax.servlet.ServletContext.getNamedDispatcher()
方法的一些代码示例,展示了ServletContext.getNamedDispatcher()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletContext.getNamedDispatcher()
方法的具体详情如下:
包路径:javax.servlet.ServletContext
类名称:ServletContext
方法名:getNamedDispatcher
[英]Returns a RequestDispatcher object that acts as a wrapper for the named servlet.
Servlets (and JSP pages also) may be given names via server administration or via a web application deployment descriptor. A servlet instance can determine its name using ServletConfig#getServletName.
This method returns null
if the ServletContext
cannot return a RequestDispatcher
for any reason.
[中]
代码示例来源:origin: spring-projects/spring-framework
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Assert.state(this.servletContext != null, "No ServletContext set");
RequestDispatcher rd = this.servletContext.getNamedDispatcher(this.defaultServletName);
if (rd == null) {
throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet '" +
this.defaultServletName + "'");
}
rd.forward(request, response);
}
代码示例来源:origin: igniterealtime/Openfire
@Override
public RequestDispatcher getNamedDispatcher( String s )
{
return proxy.getNamedDispatcher( s );
}
代码示例来源:origin: spring-projects/spring-framework
/**
* If the {@code defaultServletName} property has not been explicitly set,
* attempts to locate the default Servlet using the known common
* container-specific names.
*/
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
if (!StringUtils.hasText(this.defaultServletName)) {
if (this.servletContext.getNamedDispatcher(COMMON_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = COMMON_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(GAE_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = GAE_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(RESIN_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = RESIN_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(WEBLOGIC_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = WEBLOGIC_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(WEBSPHERE_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = WEBSPHERE_DEFAULT_SERVLET_NAME;
}
else {
throw new IllegalStateException("Unable to locate the default servlet for serving static content. " +
"Please set the 'defaultServletName' property explicitly.");
}
}
}
代码示例来源:origin: oblac/jodd
/**
* Include named resource.
*/
public static boolean includeNamed(final ServletContext context, final ServletRequest request, final ServletResponse response, final String page) throws IOException, ServletException {
RequestDispatcher dispatcher = context.getNamedDispatcher(page);
if (dispatcher != null) {
dispatcher.include(request, response);
return true;
}
return false;
}
代码示例来源:origin: oblac/jodd
/**
* Forward to named resource.
*/
public static boolean forwardNamed(final ServletContext context, final ServletRequest request, final ServletResponse response, final String resource) throws IOException, ServletException {
RequestDispatcher dispatcher = context.getNamedDispatcher(resource);
if (dispatcher != null) {
dispatcher.forward(request, response);
return true;
}
return false;
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Assert.state(this.servletContext != null, "No ServletContext set");
RequestDispatcher rd = this.servletContext.getNamedDispatcher(this.defaultServletName);
if (rd == null) {
throw new IllegalStateException("A RequestDispatcher could not be located for the default servlet '" +
this.defaultServletName + "'");
}
rd.forward(request, response);
}
代码示例来源:origin: org.springframework/spring-webmvc
/**
* If the {@code defaultServletName} property has not been explicitly set,
* attempts to locate the default Servlet using the known common
* container-specific names.
*/
@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
if (!StringUtils.hasText(this.defaultServletName)) {
if (this.servletContext.getNamedDispatcher(COMMON_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = COMMON_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(GAE_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = GAE_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(RESIN_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = RESIN_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(WEBLOGIC_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = WEBLOGIC_DEFAULT_SERVLET_NAME;
}
else if (this.servletContext.getNamedDispatcher(WEBSPHERE_DEFAULT_SERVLET_NAME) != null) {
this.defaultServletName = WEBSPHERE_DEFAULT_SERVLET_NAME;
}
else {
throw new IllegalStateException("Unable to locate the default servlet for serving static content. " +
"Please set the 'defaultServletName' property explicitly.");
}
}
}
代码示例来源:origin: spring-projects/spring-framework
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
ServletContext servletContext = getServletContext();
Assert.state(servletContext != null, "No ServletContext");
RequestDispatcher rd = servletContext.getNamedDispatcher(this.servletName);
if (rd == null) {
throw new ServletException("No servlet with name '" + this.servletName + "' defined in web.xml");
}
// If already included, include again, else forward.
if (useInclude(request, response)) {
rd.include(request, response);
if (logger.isTraceEnabled()) {
logger.trace("Included servlet [" + this.servletName +
"] in ServletForwardingController '" + this.beanName + "'");
}
}
else {
rd.forward(request, response);
if (logger.isTraceEnabled()) {
logger.trace("Forwarded to servlet [" + this.servletName +
"] in ServletForwardingController '" + this.beanName + "'");
}
}
return null;
}
代码示例来源:origin: org.springframework/spring-webmvc
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
throws Exception {
ServletContext servletContext = getServletContext();
Assert.state(servletContext != null, "No ServletContext");
RequestDispatcher rd = servletContext.getNamedDispatcher(this.servletName);
if (rd == null) {
throw new ServletException("No servlet with name '" + this.servletName + "' defined in web.xml");
}
// If already included, include again, else forward.
if (useInclude(request, response)) {
rd.include(request, response);
if (logger.isTraceEnabled()) {
logger.trace("Included servlet [" + this.servletName +
"] in ServletForwardingController '" + this.beanName + "'");
}
}
else {
rd.forward(request, response);
if (logger.isTraceEnabled()) {
logger.trace("Forwarded to servlet [" + this.servletName +
"] in ServletForwardingController '" + this.beanName + "'");
}
}
return null;
}
代码示例来源:origin: Atmosphere/atmosphere
servlet.service(request, response);
} else {
RequestDispatcher rd = configImpl.getServletContext().getNamedDispatcher("default");
if (rd == null) {
throw new ServletException("No Servlet Found");
代码示例来源:origin: spring-projects/spring-framework
private void doTestServletForwardingController(ServletForwardingController sfc, boolean include)
throws Exception {
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ServletContext context = mock(ServletContext.class);
RequestDispatcher dispatcher = mock(RequestDispatcher.class);
given(request.getMethod()).willReturn("GET");
given(context.getNamedDispatcher("action")).willReturn(dispatcher);
if (include) {
given(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).willReturn("somePath");
}
else {
given(request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE)).willReturn(null);
}
StaticWebApplicationContext sac = new StaticWebApplicationContext();
sac.setServletContext(context);
sfc.setApplicationContext(sac);
assertNull(sfc.handleRequest(request, response));
if (include) {
verify(dispatcher).include(request, response);
}
else {
verify(dispatcher).forward(request, response);
}
}
代码示例来源:origin: b3log/latke
/**
* Public construct with specified servlet context.
*
* @param servletContext the specified servlet context
*/
public StaticResourceHandler(final ServletContext servletContext) {
for (final String servletName : OPTION_SERVLET_NAME) {
requestDispatcher = servletContext.getNamedDispatcher(servletName);
if (null != requestDispatcher) {
defaultServletName = servletName;
break;
}
}
if (null == requestDispatcher) {
throw new IllegalStateException(
"Unable to locate the default servlet for serving static content. "
+ "Please report this issue on https://github.com/b3log/latke/issues/new");
}
LOGGER.log(Level.DEBUG, "The default servlet for serving static resource is [{0}]", defaultServletName);
}
代码示例来源:origin: opensourceBIM/BIMserver
protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo) throws ServletException {
String theServletPath = dispatcherServletPath == null ? "/" : dispatcherServletPath;
ServletContext sc = super.getServletContext();
RequestDispatcher rd = dispatcherServletName != null ? sc.getNamedDispatcher(dispatcherServletName) : sc.getRequestDispatcher(theServletPath + pathInfo);
if (rd == null) {
throw new ServletException("No RequestDispatcher can be created for path " + pathInfo);
}
try {
HttpServletRequestFilter servletRequest = new HttpServletRequestFilter(request, pathInfo, theServletPath);
rd.forward(servletRequest, response);
} catch (Throwable ex) {
throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed");
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
protected void redirect(HttpServletRequest request, HttpServletResponse response, String pathInfo)
throws ServletException {
boolean customServletPath = dispatcherServletPath != null;
String theServletPath = customServletPath ? dispatcherServletPath : "/";
ServletContext sc = super.getServletContext();
RequestDispatcher rd = dispatcherServletName != null
? sc.getNamedDispatcher(dispatcherServletName)
: sc.getRequestDispatcher((theServletPath + pathInfo).replace("//", "/"));
if (rd == null) {
String errorMessage = "No RequestDispatcher can be created for path " + pathInfo;
if (dispatcherServletName != null) {
errorMessage += ", dispatcher name: " + dispatcherServletName;
}
throw new ServletException(errorMessage);
}
try {
for (Map.Entry<String, String> entry : redirectAttributes.entrySet()) {
request.setAttribute(entry.getKey(), entry.getValue());
}
HttpServletRequest servletRequest =
new HttpServletRequestRedirectFilter(request, pathInfo, theServletPath, customServletPath);
if (PropertyUtils.isTrue(getServletConfig().getInitParameter(REDIRECT_WITH_INCLUDE_PARAMETER))) {
rd.include(servletRequest, response);
} else {
rd.forward(servletRequest, response);
}
} catch (Throwable ex) {
throw new ServletException("RequestDispatcher for path " + pathInfo + " has failed", ex);
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.http.base
@Override
public RequestDispatcher getNamedDispatcher(String name)
{
return delegatee.getNamedDispatcher(name);
}
代码示例来源:origin: apache/felix
@Override
public RequestDispatcher getNamedDispatcher(String name)
{
return delegatee.getNamedDispatcher(name);
}
代码示例来源:origin: io.joynr.java.messaging/servlet-common
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
RequestDispatcher requestDispatcher = getServletContext().getNamedDispatcher("default");
requestDispatcher.forward(req, resp);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-common
@Private
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
RequestDispatcher rd = getServletContext().getNamedDispatcher("default");
HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {
public String getServletPath() {
return "";
}
};
rd.forward(wrapped, resp);
}
代码示例来源:origin: com.github.jiayuhan-it/hadoop-yarn-common
@Private
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
RequestDispatcher rd = getServletContext().getNamedDispatcher("default");
HttpServletRequest wrapped = new HttpServletRequestWrapper(req) {
public String getServletPath() {
return "";
}
};
rd.forward(wrapped, resp);
}
代码示例来源:origin: apache/cxf
protected RequestDispatcher getRequestDispatcher(ServletContext sc, Class<?> clazz, String path) {
RequestDispatcher rd = dispatcherName != null ? sc.getNamedDispatcher(dispatcherName)
: sc.getRequestDispatcher(path);
if (rd == null) {
String message =
new org.apache.cxf.common.i18n.Message("RESOURCE_PATH_NOT_FOUND",
BUNDLE, path).toString();
LOG.severe(message);
throw ExceptionUtils.toInternalServerErrorException(null, null);
}
return rd;
}
内容来源于网络,如有侵权,请联系作者删除!