?? actiontool.java
字號(hào):
package tools;
import javax.servlet.http.HttpServletRequest;
import action.MyAction;
import config.MyBean;
import config.MyConfig;
import config.MyForward;
import config.MyMap;
import exception.ActionHasError;
import exception.FormHasError;
import exception.ForwardHasError;
public class ActionTool {
//得到轉(zhuǎn)發(fā)地址
public static String getSendAddress(MyConfig config,String forward)throws ForwardHasError{
boolean flag = false;
MyForward[] myforward = config.getMyforward();
for(int i=0;i<myforward.length;i++){
if(myforward[i].getName().equals(forward)){
flag = true;
return myforward[i].getPath();
}
}
if(!flag){
throw new ForwardHasError();
}
return null;
}
//得到action對(duì)象
public static MyAction getMyAction(HttpServletRequest request,MyConfig config)throws Exception{
String uri = request.getRequestURI();
String path = UtilTool.getRequestPath(uri);
String actionClass = getActionClass(config,path);
MyAction action = (MyAction)Class.forName(actionClass).newInstance();
return action;
}
static String getActionClass(MyConfig config, String thePath) throws ActionHasError{
boolean flag = false;
MyMap[] mymap = config.getMymap();
for (int i = 0; i < mymap.length; i++) {
if (thePath != null && thePath.equals(mymap[i].getPath())) {
return mymap[i].getType();
}
}
if(!flag){
System.out.println("沒(méi)有action");
throw new ActionHasError();
}
return null;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -