本文整理汇总了Java中javax.servlet.ServletContext.getContextPath方法的典型用法代码示例。如果您正苦于以下问题:Java ServletContext.getContextPath方法的具体用法?Java ServletContext.getContextPath怎么用?Java ServletContext.getContextPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.ServletContext
的用法示例。
在下文中一共展示了ServletContext.getContextPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSaveUrlPrefixNormal
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Test
public void testSaveUrlPrefixNormal(@Mocked ServletContext servletContext,
@Mocked ServletRegistration servletRegistration) {
System.clearProperty(Const.URL_PREFIX);
new Expectations() {
{
servletContext.getContextPath();
result = "/root";
servletRegistration.getClassName();
result = RestServlet.class.getName();
servletRegistration.getMappings();
result = Arrays.asList("/rest/*");
servletContext.getServletRegistrations();
result = Collections.singletonMap("test", servletRegistration);
}
};
ServletUtils.saveUrlPrefix(servletContext);
Assert.assertThat(System.getProperty(Const.URL_PREFIX), Matchers.is("/root/rest"));
System.clearProperty(Const.URL_PREFIX);
}
示例2: init
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
ServletContext servletContext = config.getServletContext();
logger.info("limberest context path: {}: " + servletContext.getContextPath());
String warDeployPath = servletContext.getRealPath("/");
logger.debug("warDeployPath: {}", warDeployPath);
String webappContextPath = servletContext.getContextPath();
logger.debug("webappContextPath: {}", webappContextPath);
try {
// TODO log
new Initializer().scan();
}
catch (IOException ex) {
logger.error("Unable to scan all packages", ex);
}
}
示例3: collectUrlPrefix
import javax.servlet.ServletContext; //导入方法依赖的package包/类
static String collectUrlPrefix(ServletContext servletContext, Class<?> servletCls) {
String[] urlPatterns = collectUrlPatterns(servletContext, servletCls);
if (urlPatterns.length == 0) {
return null;
}
// even have multiple urlPattern, we only choose a to set as urlPrefix
// only make sure sdk can invoke
String urlPattern = urlPatterns[0];
return servletContext.getContextPath() + urlPattern.substring(0, urlPattern.length() - 2);
}
示例4: doExport
import javax.servlet.ServletContext; //导入方法依赖的package包/类
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
String addr = url.getIp() + ":" + url.getPort();
Class implClass = ServiceClassHolder.getInstance().popServiceClass();
RestServer server = servers.get(addr);
if (server == null) {
server = serverFactory.createServer(url.getParameter(Constants.SERVER_KEY, "jetty"));
server.start(url);
servers.put(addr, server);
}
String contextPath = getContextPath(url);
if ("servlet".equalsIgnoreCase(url.getParameter(Constants.SERVER_KEY, "jetty"))) {
ServletContext servletContext = ServletManager.getInstance().getServletContext(ServletManager.EXTERNAL_SERVER_PORT);
if (servletContext == null) {
throw new RpcException("No servlet context found. Since you are using server='servlet', " +
"make sure that you've configured " + BootstrapListener.class.getName() + " in web.xml");
}
String webappPath = servletContext.getContextPath();
if (StringUtils.isNotEmpty(webappPath)) {
webappPath = webappPath.substring(1);
if (!contextPath.startsWith(webappPath)) {
throw new RpcException("Since you are using server='servlet', " +
"make sure that the 'contextpath' property starts with the path of external webapp");
}
contextPath = contextPath.substring(webappPath.length());
if (contextPath.startsWith("/")) {
contextPath = contextPath.substring(1);
}
}
}
final Class resourceDef = GetRestful.getRootResourceClass(implClass) != null ? implClass : type;
server.deploy(resourceDef, impl, contextPath);
final RestServer s = server;
return new Runnable() {
public void run() {
// TODO due to dubbo's current architecture,
// it will be called from registry protocol in the shutdown process and won't appear in logs
s.undeploy(resourceDef);
}
};
}
示例5: init
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void init(FilterConfig filterConfig) throws ServletException {
logger.debug("init...");
long start = System.currentTimeMillis();
// 获取配置类
String configClass = filterConfig.getInitParameter("configClass");
createDispatcherConfig(configClass);
ServletContext servletContext = filterConfig.getServletContext();
String realPath = servletContext.getRealPath("/");
logger.info("webRootPath:{}", realPath);
Constants.me().setWebRootPath(new File(realPath));
config();
BeanFactory.getInject().injectMembers(ViewManager.me());
ViewManager.me().init(servletContext);
String contextPath = servletContext.getContextPath();
logger.info("contextPath:{}", contextPath);
contextPathLength = (contextPath == null || "/".equals(contextPath) ? 0 : contextPath.length());
actionHandler = BeanFactory.getBean(ActionHandler.class);
actionHandler.init(contextPath);
actionConfig.afterStart();
long end = System.currentTimeMillis();
logger.info("init {} ms", (end - start));
}
示例6: setServletContext
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void setServletContext(ServletContext servletContext) {
this.serverRootUrl = servletContext.getContextPath();
}
开发者ID:graphium-project,项目名称:graphium,代码行数:5,代码来源:AbstractServerUrlAndAuthenticationAwareHttpNotifier.java
示例7: dispatch
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void dispatch(final ServletContext context, final String path) {
if (dispatched) {
throw UndertowServletMessages.MESSAGES.asyncRequestAlreadyDispatched();
}
HttpServletRequestImpl requestImpl = servletRequestContext.getOriginalRequest();
HttpServletResponseImpl responseImpl = servletRequestContext.getOriginalResponse();
final HttpServerExchange exchange = requestImpl.getExchange();
exchange.getAttachment(ServletRequestContext.ATTACHMENT_KEY).setDispatcherType(DispatcherType.ASYNC);
requestImpl.setAttribute(ASYNC_REQUEST_URI, requestImpl.getOriginalRequestURI());
requestImpl.setAttribute(ASYNC_CONTEXT_PATH, requestImpl.getOriginalContextPath());
requestImpl.setAttribute(ASYNC_SERVLET_PATH, requestImpl.getOriginalServletPath());
requestImpl.setAttribute(ASYNC_QUERY_STRING, requestImpl.getOriginalQueryString());
String newQueryString = "";
int qsPos = path.indexOf("?");
String newServletPath = path;
if (qsPos != -1) {
newQueryString = newServletPath.substring(qsPos + 1);
newServletPath = newServletPath.substring(0, qsPos);
}
String newRequestUri = context.getContextPath() + newServletPath;
//todo: a more efficient impl
Map<String, Deque<String>> newQueryParameters = new HashMap<>();
for (String part : newQueryString.split("&")) {
String name = part;
String value = "";
int equals = part.indexOf('=');
if (equals != -1) {
name = part.substring(0, equals);
value = part.substring(equals + 1);
}
Deque<String> queue = newQueryParameters.get(name);
if (queue == null) {
newQueryParameters.put(name, queue = new ArrayDeque<>(1));
}
queue.add(value);
}
requestImpl.setQueryParameters(newQueryParameters);
requestImpl.getExchange().setRelativePath(newServletPath);
requestImpl.getExchange().setQueryString(newQueryString);
requestImpl.getExchange().setRequestPath(newRequestUri);
requestImpl.getExchange().setRequestURI(newRequestUri);
requestImpl.setServletContext((ServletContextImpl) context);
responseImpl.setServletContext((ServletContextImpl) context);
Deployment deployment = requestImpl.getServletContext().getDeployment();
ServletPathMatch info = deployment.getServletPaths().getServletHandlerByPath(newServletPath);
requestImpl.getExchange().getAttachment(ServletRequestContext.ATTACHMENT_KEY).setServletPathMatch(info);
dispatchAsyncRequest(deployment.getServletDispatcher(), info, exchange);
}
示例8: generateBasePath
import javax.servlet.ServletContext; //导入方法依赖的package包/类
private static String generateBasePath(final ServletContextEvent servletContextEvent) {
final ServletContext servletContext = servletContextEvent.getServletContext();
String base = getInitParameterOrDefault(servletContext, PROPERTY_BASE, DEFAULT_BASE);
return base + servletContext.getContextPath();
}
示例9: contextInitialized
import javax.servlet.ServletContext; //导入方法依赖的package包/类
@Override
public void contextInitialized(ServletContextEvent sce) {
// TODO Auto-generated method stub
ServletContext servletContext = sce.getServletContext();
System.out.println("getContextPath:"+servletContext.getContextPath());
contextPath = servletContext.getContextPath();
//云数据同步
if(!"local".equals(DiaowenProperty.DWSTORAGETYPE)){
}
}