本文整理匯總了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);
}
}