关闭

jeeCmsV7-src 源码解析之七(前台页面初始化是request赋值)

194人阅读 评论(0) 收藏 举报
分类:

问题:当输入http://localhost:8070/jeeCms/时,通过拦截器“/”后台时,request 中包含了很多值是哪里来的?

回答:

 1、加载web.xml

<!-- 前台控制 --> 
	<servlet>
		<servlet-name>JeeCmsFront</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>
				/WEB-INF/config/jeecms-servlet-front.xml
				/WEB-INF/config/plug/**/*-servlet-front-action.xml
			</param-value>
		</init-param>
		<load-on-startup>2</load-on-startup>
	</servlet>


2、其初使化方法中 进入jeecms-servlet-front.xml,初使化:

<bean id="frontContextInterceptor" class="com.jeecms.cms.web.FrontContextInterceptor"/>

3. 为reques和中放入值

/**
 * CMS上下文信息拦截器
 * 
 * 包括登录信息、权限信息、站点信息
 */
public class FrontContextInterceptor extends HandlerInterceptorAdapter {
	public static final String SITE_COOKIE = "_site_id_cookie";
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler)
			throws ServletException {
		CmsSite site = null;
		List<CmsSite> list = cmsSiteMng.getListFromCache();
		int size = list.size();
		if (size == 0) {
			throw new RuntimeException("no site record in database!");
		} else if (size == 1) {
			site = list.get(0);
		} else {
			String server = request.getServerName();
			String alias, redirect;
			for (CmsSite s : list) {
				// 检查域名
				if (s.getDomain().equals(server)) {
					site = s;
					break;
				}
				// 检查域名别名
				alias = s.getDomainAlias();
				if (!StringUtils.isBlank(alias)) {
					for (String a : StringUtils.split(alias, ',')) {
						if (a.equals(server)) {
							site = s;
							break;
						}
					}
				}
				// 检查重定向
				redirect = s.getDomainRedirect();
				if (!StringUtils.isBlank(redirect)) {
					for (String r : StringUtils.split(redirect, ',')) {
						if (r.equals(server)) {
							try {
								response.sendRedirect(s.getUrl());
							} catch (IOException e) {
								throw new RuntimeException(e);
							}
							return false;
						}
					}
				}
			}
			if (site == null) {
				throw new SiteNotFoundException(server);
			}
		}
		
		<span style="background-color: rgb(204, 153, 51);">CmsUtils.setSite(request, site);</span>
		CmsThreadVariable.setSite(site);
		Subject subject = SecurityUtils.getSubject();
		if (subject.isAuthenticated()|| subject.isRemembered()) {
			String username =  (String) subject.getPrincipal();
			CmsUser user = cmsUserMng.findByUsername(username);
			CmsUtils.setUser(request, user);
			// Site加入线程变量
			CmsThreadVariable.setUser(user);
		}
		createJsessionId(request, response, site);
		return true;
	}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16101次
    • 积分:633
    • 等级:
    • 排名:千里之外
    • 原创:49篇
    • 转载:3篇
    • 译文:0篇
    • 评论:0条