本文整理了Java中javax.servlet.http.HttpSession.getServletContext()
方法的一些代码示例,展示了HttpSession.getServletContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpSession.getServletContext()
方法的具体详情如下:
包路径:javax.servlet.http.HttpSession
类名称:HttpSession
方法名:getServletContext
[英]Returns the ServletContext to which this session belongs.
[中]返回此会话所属的ServletContext。
代码示例来源:origin: alibaba/druid
public WebAppStat getWebAppStat(HttpServletRequest request) {
if (webAppStat != null) {
return webAppStat;
}
ServletContext context = request.getSession().getServletContext();
String contextPath = DruidWebUtils.getContextPath(context);
webAppStat = WebAppStatManager.getInstance().getWebAppStat(contextPath);
return webAppStat;
}
代码示例来源:origin: apache/geode
@Override
public void call(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession();
// Hack to expose the session to our test context
session.getServletContext().setAttribute("session", session);
session.setAttribute("lastAccessTime", session.getLastAccessedTime());
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
session.setAttribute("somethingElse", 1);
request.getSession();
response.getWriter().write("done");
}
};
代码示例来源:origin: spring-projects/spring-session
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
HttpSession session = wrappedRequest.getSession();
session.invalidate();
// no exception
session.getServletContext();
}
});
代码示例来源:origin: primefaces/primefaces
protected FileItemFactory createFileItemFactory(HttpServletRequest httpServletRequest) {
DiskFileItemFactory diskFileItemFactory = new DiskFileItemFactory();
if (thresholdSize != null) {
diskFileItemFactory.setSizeThreshold(Integer.valueOf(thresholdSize));
}
if (uploadDir != null) {
diskFileItemFactory.setRepository(new File(uploadDir));
}
FileCleaningTracker fileCleaningTracker = FileCleanerCleanup.getFileCleaningTracker(httpServletRequest.getSession().getServletContext());
if (fileCleaningTracker != null) {
diskFileItemFactory.setFileCleaningTracker(fileCleaningTracker);
}
return diskFileItemFactory;
}
}
代码示例来源:origin: geoserver/geoserver
url =
httpServletRequest
.getSession()
.getServletContext()
.getInitParameter(PROXY_PARAM);
代码示例来源:origin: geoserver/geoserver
url =
httpServletRequest
.getSession()
.getServletContext()
.getInitParameter(PROXY_PARAM);
代码示例来源:origin: spring-projects/spring-session
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
ServletContext context = wrappedRequest.getSession().getServletContext();
assertThat(context).isSameAs(expectedContext);
}
});
代码示例来源:origin: spring-projects/spring-session
@Override
public void doFilter(HttpServletRequest wrappedRequest) {
ServletContext context = wrappedRequest.getSession().getServletContext();
assertThat(context).isSameAs(wrappedRequest.getServletContext());
}
});
代码示例来源:origin: igniterealtime/Openfire
/**
* Creates a unfiltered list pager.
*
* @param request the request object for the page in question
* @param response the response object for the page in question
* @param items the complete list of items to display on the page
* @param filter the filter to apply to the complete list
* @param additionalFormFields 0 or more input field identifiers (<strong>NOT form field names</strong>) to include in requests for other pages
*/
public ListPager(final HttpServletRequest request, final HttpServletResponse response, final List<T> items, final Predicate<T> filter, final String... additionalFormFields) {
final HttpSession session = request.getSession();
final WebManager webManager = new WebManager();
webManager.init(request, response, session, session.getServletContext());
final String requestURI = request.getRequestURI();
final int initialPageSize = webManager.getRowsPerPage(requestURI, DEFAULT_PAGE_SIZE);
final List<T> filteredItems = items.stream().filter(filter).collect(Collectors.toList());
this.request = request;
this.totalItemCount = items.size();
this.filteredItemCount = filteredItems.size();
this.pageSize = bound(ParamUtils.getIntParameter(request, REQUEST_PARAMETER_KEY_PAGE_SIZE, initialPageSize), 1, PAGE_SIZES[PAGE_SIZES.length - 1]);
// Even with no filtered items, we want to display at least one page
this.totalPages = Math.max(1, (int) Math.ceil((double)filteredItemCount / (double)pageSize));
// Bound the current page between 1 and the total number of pages
this.currentPage = bound(ParamUtils.getIntParameter(request, REQUEST_PARAMETER_KEY_CURRENT_PAGE, 1), 1, totalPages);
this.firstItemOnPage = filteredItemCount == 0 ? 0 : (currentPage - 1) * pageSize + 1;
this.lastItemOnPage = filteredItemCount == 0 ? 0 : Math.min(currentPage * pageSize, filteredItemCount);
this.itemsOnPage = filteredItemCount == 0 ? Collections.emptyList() : filteredItems.subList(firstItemOnPage - 1, lastItemOnPage);
this.additionalFormFields = additionalFormFields;
webManager.setRowsPerPage(requestURI, pageSize);
}
代码示例来源:origin: oblac/jodd
protected ActionRequest createActionRequest(String actionPath) {
HttpServletRequest servletRequest = mock(HttpServletRequest.class);
HttpServletResponse servletResponse = mock(HttpServletResponse.class);
HttpSession httpSession = mock(HttpSession.class);
ServletContext servletContext = mock(ServletContext.class);
when(servletRequest.getSession()).thenReturn(httpSession);
when(httpSession.getServletContext()).thenReturn(servletContext);
MadvocController madvocController = new MadvocController();
Object action = new Object();
ActionRuntime actionRuntime = new ActionRuntime(
null,
Action.class,
ClassUtil.findMethod(Action.class, "view"),
null, null,
new ActionDefinition(actionPath, "GET"),
ServletDispatcherActionResult.class, null, false, false, null, null);
return new ActionRequest(madvocController, actionRuntime.getActionPath(), MadvocUtil.splitPathToChunks(actionRuntime.getActionPath()), actionRuntime, action, servletRequest, servletResponse);
}
代码示例来源:origin: banq/jdonframework
public HttpServletRequestWrapper(HttpServletRequest request) {
this.request = request;
AppContextWrapper acw = new ServletContextWrapper(request.getSession().getServletContext());
SessionWrapper sw = new HttpSessionWrapper(request.getSession());
this.contextHolder = new ContextHolder(acw, sw);
}
代码示例来源:origin: com.alibaba/druid
public WebAppStat getWebAppStat(HttpServletRequest request) {
if (webAppStat != null) {
return webAppStat;
}
ServletContext context = request.getSession().getServletContext();
String contextPath = DruidWebUtils.getContextPath(context);
webAppStat = WebAppStatManager.getInstance().getWebAppStat(contextPath);
return webAppStat;
}
代码示例来源:origin: banq/jdonframework
/**
* get this Web application's container
*
* @param request
* HttpServletRequest
* @return ContainerWrapper
* @throws Exception
*/
public static ContainerWrapper getContainer(HttpServletRequest request) throws Exception {
ContainerFinderImp scf = new ContainerFinderImp();
ServletContext sc = request.getSession().getServletContext();
return scf.findContainer(new ServletContextWrapper(sc));
}
代码示例来源:origin: banq/jdonframework
/**
* create a HttpServletRequestWrapper with session supports. this method
* will create HttpSession.
*
* @param request
* @return
*/
public static RequestWrapper create(HttpServletRequest request) {
HttpSession session = request.getSession();
AppContextWrapper acw = new ServletContextWrapper(session.getServletContext());
SessionWrapper sw = new HttpSessionWrapper(session);
ContextHolder contextHolder = new ContextHolder(acw, sw);
return new HttpServletRequestWrapper(request, contextHolder);
}
代码示例来源:origin: banq/jdonframework
public static Object getService(TargetMetaDef targetMetaDef, HttpServletRequest request) {
ServletContext sc = request.getSession().getServletContext();
ServiceFacade serviceFacade = new ServiceFacade();
ServiceFactory serviceFactory = serviceFacade.getServiceFactory(new ServletContextWrapper(sc));
RequestWrapper requestW = RequestWrapperFactory.create(request);
return serviceFactory.getService(targetMetaDef, requestW);
}
代码示例来源:origin: banq/jdonframework
/**
* get a component that registered in container. the component is not
* different from the service. the component instance is single instance Any
* intercepter will be disable
*
*/
public static Object getComponentInstance(String name, HttpServletRequest request) {
ServletContext sc = request.getSession().getServletContext();
ContainerWrapper containerWrapper = scf.findContainer(new ServletContextWrapper(sc));
if (!containerWrapper.isStart()) {
Debug.logError("JdonFramework not yet started, please try later ", module);
return null;
}
return containerWrapper.lookup(name);
}
代码示例来源:origin: banq/jdonframework
ServletContext sc = request.getSession().getServletContext();
ServiceFacade serviceFacade = new ServiceFacade();
ServiceFactory serviceFactory = serviceFacade.getServiceFactory(new ServletContextWrapper(sc));
代码示例来源:origin: banq/jdonframework
ServletContext sc = request.getSession().getServletContext();
Service service = serviceFacade.getService(new ServletContextWrapper(sc));
RequestWrapper requestW = RequestWrapperFactory.create(request);
代码示例来源:origin: com.khubla.pragmatach/pragmatach-framework
/**
* servlet context
*/
public ServletContext getServletContext() {
return httpServletRequest.getSession().getServletContext();
}
代码示例来源:origin: net.servicegrid/jp.go.nict.langrid.commons
public ServletServiceContext(
HttpServletRequest request,
Iterable<RpcHeader> requestRpcHeaders
){
this.request = request;
this.requestRpcHeaders = requestRpcHeaders;
this.servletContext = request.getSession().getServletContext();
String user = request.getRemoteUser();
if(user != null){
this.authorizedUserId = user;
}
}
内容来源于网络,如有侵权,请联系作者删除!