⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 servletdispatcher.java

📁 mvc框架
💻 JAVA
字号:
package com.strutslet.core;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.strutslet.model.ActionForward;
import com.strutslet.model.ActionModel;
import com.strutslet.util.Constant;

/**
 * 默认实现的Dispacher
 * @author dennis
 *
 */

public class ServletDispatcher implements Dispatcher {

	private ServletContext context;
	private static final Log log=LogFactory.getLog(ServletDispatcher.class);

	public String getNextPage(HttpServletRequest request, ServletContext context) {
		setServletContext(context);

		Map<String, ActionModel> actions = (Map<String, ActionModel>) context
				.getAttribute(Constant.ACTIONS_ATTR);
		String reqPath = (String) request.getAttribute(Constant.REQUEST_ATTR);
		ActionModel actionModel = actions.get(reqPath);
		String forward_name = "";
		ActionForward actionForward;
		try {
			Class c = Class.forName(actionModel.getClassName());
			Action action = (Action) c.newInstance();
			actionForward = action.execute(request, context);
			forward_name = actionForward.getName();
			
		} catch (Exception e) {
			log.error("can not find action "+actionModel.getClassName());
			e.printStackTrace();
		}

		actionForward = actionModel.getForwards().get(forward_name);
		if (actionForward == null) {
			log.error("can not find page for forward "+forward_name);
			return null;
		} else
			return actionForward.getViewUrl();
	}

	public void setServletContext(ServletContext context) {
		this.context = context;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -