62,616
社区成员
发帖
与我相关
我的任务
分享
if(str.equal("1")){
}else if(str.equal("1")){
}else if(str.equal("1")){
}else .......
if(a==1){;}
else if(b==1){;}
if(a==1){;}
if(a!=1&&b==1){;}
Map m = new HashMap();
m.put("download","下载");
m.put("upload","上传");
...
m.put("sort","排序");
Iterator ite = m.keySet().iterator();
while (ite.hasNext()) {
String key = (String)ite.next();
if (cmd.equals(key)) {
log.info(m.get(key).toString());
break;
}
}
public ActionForward command(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
String cmd=request.getParameter("cmd").trim();//指令名,对应CommandProcess中的方法名
/*
* 指令列表
* 下载文件:cmd=download&file=product/mlns/C053.gif&userid=1
* 注册:cmd=register
* 登陆:cmd=login&userid=1&psw=jh45dd
* 修改密码:cmd=changePsw&userid=1&oldpswjh45dd&newpsw=kl8547
*/
CommandProcess commandProcess=new CommandProcess(request,response);
Method method = null;
try {
method = commandProcess.getClass().getMethod(cmd);
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
// TODO Auto-generated catch block
log.info("找不到名为"+cmd+"的方法!请注意大小写!"+e.getMessage());
}
try {
method.invoke(commandProcess);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}