Search in sources :

Example 66 with HttpSession

use of javax.servlet.http.HttpSession in project nutz by nutzam.

the class AbstractPathView method createContext.

/**
     * 为一次 HTTP 请求,创建一个可以被表达式引擎接受的上下文对象
     * 
     * @param req
     *            HTTP 请求对象
     * @param obj
     *            入口函数的返回值
     * @return 上下文对象
     */
public static Context createContext(HttpServletRequest req, Object obj) {
    Context context = Lang.context();
    // 复制全局的上下文对象
    Object globalContext = Mvcs.getServletContext().getAttribute(Loading.CONTEXT_NAME);
    if (globalContext != null) {
        context.putAll((Context) globalContext);
    }
    // 请求对象的属性列表
    Map<String, Object> req_attr = new HashMap<String, Object>();
    for (Enumeration<String> en = req.getAttributeNames(); en.hasMoreElements(); ) {
        String tem = en.nextElement();
        if (!tem.startsWith("$"))
            req_attr.put(tem, req.getAttribute(tem));
    }
    // 兼容最初的写法
    context.set("a", req_attr);
    context.set("req_attr", req_attr);
    ActionContext ac = Mvcs.getActionContext();
    if (ac != null)
        context.set("pathargs", Mvcs.getActionContext().getPathArgs());
    HttpSession session = Mvcs.getHttpSession(false);
    if (session != null) {
        Map<String, Object> session_attr = new HashMap<String, Object>();
        for (Enumeration<String> en = session.getAttributeNames(); en.hasMoreElements(); ) {
            String tem = en.nextElement();
            session_attr.put(tem, session.getAttribute(tem));
        }
        context.set("session_attr", session_attr);
    }
    // 请求的参数表,需要兼容之前的p.参数, Fix issue 418
    Map<String, String> p = new HashMap<String, String>();
    for (Object o : Lang.enum2collection(req.getParameterNames(), new ArrayList<String>())) {
        String key = (String) o;
        String value = req.getParameter(key);
        p.put(key, value);
        // 以支持直接获取请求参数
        context.set(key, value);
    }
    context.set("p", p);
    Map<String, String> u = new HashMap<String, String>();
    AtMap at = Mvcs.getAtMap();
    if (at != null) {
        for (Object o : at.keys()) {
            String key = (String) o;
            u.put(key, at.get(key));
        }
        context.set("u", u);
    }
    // 加入返回对象
    if (null != obj)
        context.set(ViewProcessor.DEFAULT_ATTRIBUTE, obj);
    return context;
}
Also used : ActionContext(org.nutz.mvc.ActionContext) Context(org.nutz.lang.util.Context) AtMap(org.nutz.mvc.config.AtMap) HashMap(java.util.HashMap) HttpSession(javax.servlet.http.HttpSession) ActionContext(org.nutz.mvc.ActionContext)

Example 67 with HttpSession

use of javax.servlet.http.HttpSession in project jodd by oblac.

the class SessionScope method remove.

public void remove(String name) {
    if (totalRegisteredDestroyableBeans() == 0) {
        return;
    }
    HttpSession session = getCurrentHttpSession();
    Map<String, BeanData> map = getSessionMap(session);
    if (map != null) {
        map.remove(name);
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) BeanData(jodd.petite.BeanData)

Example 68 with HttpSession

use of javax.servlet.http.HttpSession in project nutz by nutzam.

the class Mvcs method setLocalizationKey.

/**
     * 设置本地化字符串的键值
     * <p>
     * 如果你用的是 Nutz.Mvc 默认的本地化机制,那么你的本地字符串键值,相当于一个你目录名。 <br>
     * 比如 "zh_CN" 等
     * 
     * @param key
     *            键值
     * @return 是否设置成功
     */
public static boolean setLocalizationKey(String key) {
    HttpSession sess = getHttpSession();
    if (null == sess)
        return false;
    sess.setAttribute(LOCALE_KEY, key);
    return true;
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 69 with HttpSession

use of javax.servlet.http.HttpSession in project jodd by oblac.

the class MoveResult method render.

/**
	 * Saves action in the session under some id that is added as request parameter.
	 */
public void render(ActionRequest actionRequest, String resultValue) throws Exception {
    String resultBasePath = actionRequest.getActionConfig().getResultBasePath();
    String resultPath = resultMapper.resolveResultPathString(resultBasePath, resultValue);
    HttpServletRequest httpServletRequest = actionRequest.getHttpServletRequest();
    HttpSession session = httpServletRequest.getSession();
    String id = generateUniqueId();
    session.setAttribute(id, actionRequest);
    String path = resultPath;
    path = URLCoder.build(path).queryParam(madvocConfig.getAttributeMoveId(), id).toString();
    DispatcherUtil.redirect(httpServletRequest, actionRequest.getHttpServletResponse(), path);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) RandomString(jodd.util.RandomString)

Example 70 with HttpSession

use of javax.servlet.http.HttpSession in project jodd by oblac.

the class RequestScopeInjector method outjectMoveSource.

/**
	 * Outjects all request data from move result source, if exist.
	 */
protected void outjectMoveSource(ActionRequest actionRequest) {
    HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
    String moveId = servletRequest.getParameter(attributeMoveId);
    if (moveId != null) {
        HttpSession session = servletRequest.getSession();
        ActionRequest sourceRequest = (ActionRequest) session.getAttribute(moveId);
        session.removeAttribute(moveId);
        if (sourceRequest != null) {
            outjectAfterMove(sourceRequest);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ActionRequest(jodd.madvoc.ActionRequest) HttpSession(javax.servlet.http.HttpSession)

Aggregations

HttpSession (javax.servlet.http.HttpSession)730 HttpServletRequest (javax.servlet.http.HttpServletRequest)151 Test (org.junit.Test)110 IOException (java.io.IOException)80 HttpServletResponse (javax.servlet.http.HttpServletResponse)80 ServletException (javax.servlet.ServletException)75 ArrayList (java.util.ArrayList)65 RequestDispatcher (javax.servlet.RequestDispatcher)59 HashMap (java.util.HashMap)48 Map (java.util.Map)44 Locale (java.util.Locale)39 Properties (java.util.Properties)39 PrintWriter (java.io.PrintWriter)38 Cookie (javax.servlet.http.Cookie)27 List (java.util.List)24 SQLException (java.sql.SQLException)23 WebUser (org.compiere.util.WebUser)23 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)20 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 ModelAndView (org.springframework.web.servlet.ModelAndView)20