本文整理汇总了Java中org.glassfish.grizzly.http.server.Request.getContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java Request.getContextPath方法的具体用法?Java Request.getContextPath怎么用?Java Request.getContextPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.glassfish.grizzly.http.server.Request
的用法示例。
在下文中一共展示了Request.getContextPath方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBasePath
import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
private String getBasePath(final Request request) {
final String contextPath = request.getContextPath();
if (contextPath == null || contextPath.isEmpty()) {
return "/";
} else if (contextPath.charAt(contextPath.length() - 1) != '/') {
return contextPath + "/";
} else {
return contextPath;
}
}
示例2: getRelativeURI
import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
/**
* Get the relative URI of this request
*/
@Override
protected String getRelativeURI(final Request request) {
String uri = request.getRequestURI();
final String resourcesContextPath = request.getContextPath();
if (resourcesContextPath != null && !resourcesContextPath.isEmpty()) {
if (!uri.startsWith(resourcesContextPath)) {
return null;
}
uri = uri.substring(resourcesContextPath.length());
}
return uri;
}
示例3: containsContextPath
import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
private boolean containsContextPath(Request request) {
return request.getContextPath() != null && request.getContextPath().length() > 0;
}
示例4: service
import org.glassfish.grizzly.http.server.Request; //导入方法依赖的package包/类
@Override
public void service(Request request, Response response)
throws Exception
{
String uri = request.getRequestURI();
int pos = uri.lastIndexOf('.');
String extension = uri.substring(pos + 1);
String mediaType = EXTENSION_TO_MEDIA_TYPE.get(extension);
if (!uri.equals("/") && ( uri.contains("..") || mediaType == null) ) {
response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
return;
}
final String resourcesContextPath = request.getContextPath();
if (resourcesContextPath != null && !resourcesContextPath.isEmpty()) {
if (!uri.startsWith(resourcesContextPath)) {
response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
return;
}
uri = uri.substring(resourcesContextPath.length());
}
uri = uri.equals("/") ? uri.concat("index.html") : uri;
System.out.println(uri);
InputStream fileStream;
try {
fileStream = webRootPath == null ?
Server.class.getResourceAsStream(WEB_ROOT + uri) :
new FileInputStream(webRootPath + uri);
} catch (IOException e) {
fileStream = null;
}
if (fileStream == null) {
response.sendError(HttpStatus.NOT_FOUND_404.getStatusCode());
} else {
response.setStatus(HttpStatus.OK_200);
response.setContentType(mediaType);
ReaderWriter.writeTo(fileStream, response.getOutputStream());
}
}