本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getDispatcherType方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getDispatcherType方法的具体用法?Java HttpServletRequest.getDispatcherType怎么用?Java HttpServletRequest.getDispatcherType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getDispatcherType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的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 = CanonicalPathUtils.canonicalize(servletPath);
} else if (resolveAgainstContextRoot) {
result = servletPath + CanonicalPathUtils.canonicalize(pathInfo);
} else {
result = CanonicalPathUtils.canonicalize(result);
}
if ((result == null) || (result.isEmpty())) {
result = "/";
}
return result;
}
示例2: getPath
import javax.servlet.http.HttpServletRequest; //导入方法依赖的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;
}
示例3: doPost
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
/*
* Where a servlet has received a POST request we still require the capability to include static content.
*/
switch (req.getDispatcherType()) {
case INCLUDE:
case FORWARD:
case ERROR:
doGet(req, resp);
break;
default:
super.doPost(req, resp);
}
}
示例4: doPut
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
switch (req.getDispatcherType()) {
case INCLUDE:
case FORWARD:
case ERROR:
doGet(req, resp);
break;
default:
super.doPut(req, resp);
}
}
示例5: doDelete
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
switch (req.getDispatcherType()) {
case INCLUDE:
case FORWARD:
case ERROR:
doGet(req, resp);
break;
default:
super.doDelete(req, resp);
}
}
示例6: doOptions
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
switch (req.getDispatcherType()) {
case INCLUDE:
case FORWARD:
case ERROR:
doGet(req, resp);
break;
default:
super.doOptions(req, resp);
}
}
示例7: doTrace
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
switch (req.getDispatcherType()) {
case INCLUDE:
case FORWARD:
case ERROR:
doGet(req, resp);
break;
default:
super.doTrace(req, resp);
}
}
示例8: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
if ("y".equals(req.getParameter(DISPATCH_CHECK))) {
if (req.getDispatcherType() != DispatcherType.ASYNC) {
track("WrongDispatcherType-");
}
}
track("DispatchingServletGet-");
final int iter = Integer.parseInt(req.getParameter(ITER_PARAM)) - 1;
final AsyncContext ctxt = req.startAsync();
if (addTrackingListener) {
TrackingListener listener =
new TrackingListener(completeOnError, true, null);
ctxt.addListener(listener);
}
Runnable run = new Runnable() {
@Override
public void run() {
if (iter > 0) {
ctxt.dispatch("/stage1?" + ITER_PARAM + "=" + iter +
"&" + DISPATCH_CHECK + "=y");
} else {
ctxt.dispatch("/stage2");
}
}
};
if ("y".equals(req.getParameter("useThread"))) {
new Thread(run).start();
} else {
run.run();
}
}
示例9: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String path = getPath(req);
if (!isAllowed(path, req.getDispatcherType())) {
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
if (File.separatorChar != '/') {
//if the separator char is not / we want to replace it with a / and canonicalise
path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
}
final Resource resource;
//we want to disallow windows characters in the path
if (File.separatorChar == '/' || !path.contains(File.separator)) {
resource = resourceManager.getResource(path);
} else {
resource = null;
}
if (resource == null) {
if (req.getDispatcherType() == DispatcherType.INCLUDE) {
//servlet 9.3
throw new FileNotFoundException(path);
} else {
resp.sendError(StatusCodes.NOT_FOUND);
}
return;
} else if (resource.isDirectory()) {
if ("css".equals(req.getQueryString())) {
resp.setContentType("text/css");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
return;
} else if ("js".equals(req.getQueryString())) {
resp.setContentType("application/javascript");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
return;
}
if (directoryListingEnabled) {
StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
resp.getWriter().write(output.toString());
} else {
resp.sendError(StatusCodes.FORBIDDEN);
}
} else {
if (path.endsWith("/")) {
//UNDERTOW-432
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
serveFileBlocking(req, resp, resource);
}
}
示例10: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
String path = getPath(req);
if (!isAllowed(path, req.getDispatcherType())) {
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
if(File.separatorChar != '/') {
//if the separator char is not / we want to replace it with a / and canonicalise
path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
}
final Resource resource;
//we want to disallow windows characters in the path
if(File.separatorChar == '/' || !path.contains(File.separator)) {
resource = resourceManager.getResource(path);
} else {
resource = null;
}
if (resource == null) {
if (req.getDispatcherType() == DispatcherType.INCLUDE) {
//servlet 9.3
throw new FileNotFoundException(path);
} else {
resp.sendError(StatusCodes.NOT_FOUND);
}
return;
} else if (resource.isDirectory()) {
if ("css".equals(req.getQueryString())) {
resp.setContentType("text/css");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
return;
} else if ("js".equals(req.getQueryString())) {
resp.setContentType("application/javascript");
resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
return;
}
if (directoryListingEnabled) {
StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
resp.getWriter().write(output.toString());
} else {
resp.sendError(StatusCodes.FORBIDDEN);
}
} else {
if(path.endsWith("/")) {
//UNDERTOW-432
resp.sendError(StatusCodes.NOT_FOUND);
return;
}
serveFileBlocking(req, resp, resource);
}
}