/**
* 伪静态Servlet业务工厂
* @author RuiLin.Xie - xKF24276
*/
public class ActionBizFactory
{
//单例
private static ActionBizFactory actionBizFactory = new ActionBizFactory();
//Action键值对
private static HashMap<String, String> actionMap = new HashMap<String, String>();
//私有构造
private ActionBizFactory(){}
//得到动作业务工厂
public static ActionBizFactory getActionBizFactory()
{
return actionBizFactory;
}
/**
* 根据用户请求解析出用户动作及提交参数
* @param request
* @return
*/
public RequestPackage reqToRequestPackage(HttpServletRequest request, HttpServletResponse response)
{
RequestPackage rp = new RequestPackage();
rp.setRequest(request);
rp.setResponse(response);
String[] tmpUrl;
/**
* /PoseStaticPage/login--uname-admin--upwd-123456.html
* 得到请求的uri
*/
String uri = request.getRequestURI();
//分段截取
tmpUrl = uri.split("/");
/** 取得action与参数:login--uname-admin--upwd-123456.html **/
String tmpAct = tmpUrl[tmpUrl.length - 1];
/** 如果没参数,如POST **/
if(tmpAct.indexOf("-") == -1)
{
if(tmpAct.indexOf(".html") != -1)
tmpAct = tmpAct.substring(0, tmpAct.length() - 5);
rp.setAction(tmpAct);
return rp;
}
/** 取得Action名:login **/
tmpUrl = tmpAct.split("--");
String action = tmpUrl[0];
rp.setAction(action);
tmpAct = tmpAct.substring(action.length() + 1, tmpAct.length());
/** 所有参数字符串:login--uname-admin--upwd-123456 **/
String paramStr = tmpAct.substring(1, tmpAct.length() - 5);
String[] paramArr = paramStr.split("--");
/** 将参数存入map **/
for(int i = 0; i < paramArr.length; i++)
{
String[] tmpParams = paramArr[i].split("-");
rp.getParameter().put(tmpParams[0], (tmpParams.length <= 1 ? "" : tmpParams[1]));
}
return rp;
}
/**
* 执行动作
* @param request
* @param response
*/
public void exec(RequestPackage rp)
{
String className = getActionMap().get(rp.getAction());
//load类,并将参数rp传入
}
public static HashMap<String, String> getActionMap()
{
return actionMap;
}
public static void setActionMap(HashMap<String, String> actionMap)
{
ActionBizFactory.actionMap = actionMap;
}
}
伪静态Servlet业务工厂
最新推荐文章于 2022-08-02 08:13:45 发布