用户请求动作

/**
 * 用户请求动作
 * @author RuiLin.Xie - xKF24276
 */
public class BaseAction extends HttpServlet
{

	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * 处理Get
	 */
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		initCookie(req, resp);
		
		//根据用户请求解析出用户动作及提交参数
		RequestPackage rp = ActionBizFactory.getActionBizFactory().reqToRequestPackage(req, resp);
		
		System.out.println(rp.getAction());
		if(rp.getAction().startsWith("PoseStaticPage") || rp.getAction().length() == 0 || rp.getAction().equals("index"))
			req.getRequestDispatcher("index.jsp").forward(req, resp);
		
		//执行业务并响应用户
		ActionBizFactory.getActionBizFactory().exec(rp);
	}

	/**
	 * 处理POST
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
	{
		doGet(req, resp);
	}

	
	/**
	 * 读取配置文件初始化配置
	 */
	public void init() throws ServletException
	{
		//得到配置文件路径
		String filePath = this.getServletConfig().getServletContext().getRealPath("/"); 
		filePath = filePath + "WEB-INF\\action.conf";

		//初始化到ActionBizFactory 的 actionMap
		
		super.init();
	}
	
	/**
	 * 初始化Cookie,防止非法下载
	 * @param request
	 * @param response
	 */
	private void initCookie(HttpServletRequest request, HttpServletResponse response)
	{		
		Object oFurl = request.getSession().getAttribute("FURL");
		String ccookie = request.getHeader("Cookie");
		
		if(oFurl == null || ccookie.indexOf("FURL") == -1)
		{			
			//加密URL
			String fromUrl = request.getRequestURL().toString();
			
			Cookie cookie = new Cookie("FURL", fromUrl);
			response.addCookie(cookie);
			request.getSession().setAttribute("FURL", fromUrl);
			
		}
	}

}

你可能感兴趣的:(Web,jsp)