gpt4 book ai didi

org.directwebremoting.WebContext类的使用及代码示例

转载 作者:知者 更新时间:2024-03-22 13:15:05 26 4
gpt4 key购买 nike

本文整理了Java中org.directwebremoting.WebContext类的一些代码示例,展示了WebContext类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebContext类的具体详情如下:
包路径:org.directwebremoting.WebContext
类名称:WebContext

WebContext介绍

[英]Class to enable us to access servlet parameters. WebContext is only available from a DWR thread. If you need to access web data from a non-DWR thread, use the superclass, ServerContext.
[中]类以使我们能够访问servlet参数。WebContext仅可从DWR线程获得。如果需要从非DWR线程访问web数据,请使用超类ServerContext。

代码示例

代码示例来源:origin: stackoverflow.com

WebContext ctx = WebContextFactory.get();
HttpServletRequest request = ctx.getHttpServletRequest();

代码示例来源:origin: org.directwebremoting/dwr

public Object convertInbound(Class<?> paramType, InboundVariable data)
{
  WebContext webcx = WebContextFactory.get();
  if (HttpServletRequest.class.isAssignableFrom(paramType))
  {
    return webcx.getHttpServletRequest();
  }
  if (HttpServletResponse.class.isAssignableFrom(paramType))
  {
    return webcx.getHttpServletResponse();
  }
  if (ServletConfig.class.isAssignableFrom(paramType))
  {
    return webcx.getServletConfig();
  }
  if (ServletContext.class.isAssignableFrom(paramType))
  {
    return webcx.getServletContext();
  }
  if (HttpSession.class.isAssignableFrom(paramType))
  {
    return webcx.getSession(true);
  }
  return null;
}

代码示例来源:origin: org.directwebremoting/dwr

object = webcx.getServletContext().getAttribute(name);
object = webcx.getSession().getAttribute(name);
object = webcx.getScriptSession().getAttribute(name);
object = webcx.getHttpServletRequest().getAttribute(name);
  webcx.getServletContext().setAttribute(name, object);
  webcx.getSession().setAttribute(name, object);
  webcx.getScriptSession().setAttribute(name, object);
  webcx.getHttpServletRequest().setAttribute(name, object);

代码示例来源:origin: riotfamily/riot

/**
 * Performs a logout.
 */
@RemoteMethod
public void logout() {
  WebContext ctx = WebContextFactory.get();
  LoginManager.logout(ctx.getHttpServletRequest(), 
      ctx.getHttpServletResponse());
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

/**
 * Method responsible for generating form for reporting errors.
 * @param elementId
 * @return
 */
public Map<String, Object> getForm(String elementId) {
  Map<String, Object> result = new HashMap<String, Object>();
  try {
    Map<String, Object> model = new HashMap<String, Object>();
    WebContext context = WebContextFactory.get();
    String captchaId = captchaIdGenerator.getId(context.getSession().getId());
    model.put("captchaId", captchaId);
    model.put("extId", elementId);
    model.put("logged", false);
    model.put("timestamp", (new Date()).getTime());
    context.getHttpServletRequest().setAttribute("viewModel", model);
    String html = context.forwardToString(forcedViewName);
    result.put(DWRConstants.CONTENT, html);
  } catch (Exception e) {
    log.warn("Exception occurred when rendering DWR error form for element "
        + elementId, e);
    result.put(DWRConstants.ERROR, messageSource.getMessage(
        MessageConstants.DWR_NO_DATA, null,
        LocaleContextHolder.getLocale()));
  }
  return result;
}

代码示例来源:origin: infiniteautomation/ma-core-public

public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception {
    WebContext webContext = WebContextFactory.get();

    if (resourceBundleDirectory != null && resourceBundleLoader == null)
      resourceBundleLoader = new ResourceBundleLoader(webContext.getServletContext().getRealPath(
          resourceBundleDirectory));

    I18NUtils.prepareRequest(webContext.getHttpServletRequest(), localeResolverName, bundleBaseName,
        resourceBundleLoader);
    return chain.doFilter(obj, method, params);
  }
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

private Map<String, Object> prepareDWRModelAndView(StyledCitationVO citationView) {
  Map<String, Object> model = new HashMap<>();
  if (citationView != null) {
    model.put("styledCitation", citationView);
    try {
      WebContext context = WebContextFactory.get();
      final HttpServletRequest httpServletRequest = context.getHttpServletRequest();
      model.put("locale", localeResolver.resolveLocale(httpServletRequest).getLanguage());
      httpServletRequest.setAttribute("content", model);
      model.put(DWRConstants.CONTENT, context.forwardToString(view));
    } catch (ServletException e) {
      throw new SystemException(Modules.CATALOG, "Servlet error", e);
    } catch (IOException e) {
      throw new SystemException(Modules.CATALOG, "IO error", e);
    }
  }
  noDWRDataMessage(model);
  return model;
}

代码示例来源:origin: riotfamily/riot

private void initScriptSession() {
  WebContext webContext = WebContextFactory.get();
  HttpServletRequest request = webContext.getHttpServletRequest();
  ScriptSession currentSession = webContext.getScriptSession();
  String host = request.getServerName();
  RiotUser user = AccessController.getCurrentUser();
  currentSession.setAttribute("host", host);
  currentSession.setAttribute("userId", user.getUserId());
}

代码示例来源:origin: org.directwebremoting/dwr

public Object getInstance() throws InstantiationException
{
  // fills for the first time the moduleConfig
  ActionForm formInstance = (ActionForm) WebContextFactory.get().getSession().getAttribute(formBean);
  if (formInstance == null)
  {
    throw new InstantiationException("Can't find formInstance  for " + formBean);
  }
  return formInstance;
}

代码示例来源:origin: org.directwebremoting/dwr

/**
 * Generates and returns a new unique id suitable to use for the
 * CSRF session cookie. This method is itself exempted from CSRF checking.
 */
public String generateId()
{
  WebContext webContext = WebContextFactory.get();
  // If the current session already has a set DWRSESSIONID then we return that
  HttpServletRequest request = webContext.getHttpServletRequest();
  HttpSession sess = request.getSession(false);
  if (sess != null && sess.getAttribute(ATTRIBUTE_DWRSESSIONID) != null)
  {
    return (String) sess.getAttribute(ATTRIBUTE_DWRSESSIONID);
  }
  // Otherwise generate a fresh ID
  IdGenerator idGenerator = webContext.getContainer().getBean(IdGenerator.class);
  return idGenerator.generate();
}

代码示例来源:origin: org.directwebremoting/dwr

public Object doFilter(Object object, Method method, Object[] params, AjaxFilterChain chain) throws Exception
{
  ServletContext context = WebContextFactory.get().getServletContext();
  SessionFactory sessionFactory = (SessionFactory) context.getAttribute(ATTRIBUTE_SESSION);
  Transaction transaction = null;
  if (sessionFactory != null)
  {
    Session session = sessionFactory.getCurrentSession();
    transaction = session.beginTransaction();
  }
  else
  {
    log.error("SessionFactory not initialized for this web application. Use: H3SessionAjaxFilter.setSessionFactory(servletContext, sessionFactory);");
  }
  Object reply = chain.doFilter(object, method, params);
  if (transaction != null)
  {
    transaction.commit();
  }
  return reply;
}

代码示例来源:origin: org.directwebremoting/dwr

public ScriptSession get()
{
  WebContext webcx = WebContextFactory.get();
  return webcx.getScriptSession();
}

代码示例来源:origin: org.directwebremoting/dwr

RealScriptSession scriptSession = (RealScriptSession) webCtx.getScriptSession();
HttpSession httpSession = webCtx.getSession(false);
String httpSessionId = (httpSession != null ? httpSession.getId() : null);

代码示例来源:origin: org.directwebremoting/dwr

public HttpServletResponse get()
{
  WebContext webcx = WebContextFactory.get();
  return webcx.getHttpServletResponse();
}

代码示例来源:origin: org.directwebremoting/dwr

ScriptSession session = webContext.getScriptSession();
ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class);

代码示例来源:origin: infiniteautomation/ma-core-public

@DwrPermission(anonymous = true)
public void setLocale(String locale) {
  WebContext webContext = WebContextFactory.get();
  LocaleResolver localeResolver = new SessionLocaleResolver();
  LocaleEditor localeEditor = new LocaleEditor();
  localeEditor.setAsText(locale);
  localeResolver.setLocale(webContext.getHttpServletRequest(), webContext.getHttpServletResponse(),
      (Locale) localeEditor.getValue());
}

代码示例来源:origin: infiniteautomation/ma-core-public

public Object doFilter(Object obj, Method method, Object[] params, AjaxFilterChain chain) throws Exception {
    WebContext webContext = WebContextFactory.get();

    WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(webContext
        .getServletContext());
    MessageSource messageSource = (MessageSource) wac.getBean(messageSourceKey);

    JstlUtils.exposeLocalizationContext(webContext.getHttpServletRequest(), messageSource);

    return chain.doFilter(obj, method, params);
  }
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

try {
  String cid = captchaIdGenerator.getId(
      context.getSession().getId());
  model.put("captchaId", cid);
  model.put("extId", elementId);
  model.put("logged", false);
  model.put("timestamp", (new Date()).getTime());
  context.getHttpServletRequest().setAttribute("viewModel", model);
  String html = context.forwardToString(forcedViewName);
  result.put(DWRConstants.CONTENT, html);
} catch (Exception e) {

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

public Map<String, Object> getDetails(String elementId) {
  
  Map<String, Object> result = new HashMap<String, Object>();
  
  try {
    String viewName;
    if (elementId == null || "".equals(elementId))
      throw new SystemException(Modules.DETAILS,
          "Parameter id value not provided.");
    elementHandler.setId(elementId);
    String resolvedViewName = elementHandler.buildView();
    viewName = forcedViewName != null ? forcedViewName
        : resolvedViewName;
    WebContext context = WebContextFactory.get();
    context.getHttpServletRequest().setAttribute("viewModel",
        elementHandler.getModel());
    String html = context.forwardToString(viewName);
    result.put(DWRConstants.CONTENT, html);
  } catch (Exception e) {
    log.warn("Exception occurred when rendering DWR Part for element "
        + elementId, e);
    result.put(DWRConstants.ERROR, messageSource.getMessage(MessageConstants.DWR_NO_DATA,
        null, LocaleContextHolder.getLocale()));
  }
  return result;
}

代码示例来源:origin: riotfamily/riot

private void nofifyUsers() {
  WebContext webContext = WebContextFactory.get();
  HttpServletRequest request = webContext.getHttpServletRequest();
  final ScriptSession currentSession = webContext.getScriptSession();
  final RiotUser user = AccessController.getCurrentUser();
  final String host = request.getServerName();

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com