我现在想要用switch来判断各个国家,例如
String nation=request.getParameter("delegation");
nation=nation.trim();
String gg = new String(nation.getBytes("iso-8859-1"),"gb2312");
String file = "";
switch(gg)
{
case ("中国") : file="chn"; break; case ("法国") : file="french"; break;
case ("德国") : file="germany"; break;
default : out.println("error");
}
但是好像不行,怎么能实现这个功能呢???不会case不能以字符串为判断依据吧~~谢谢
String nation=request.getParameter("delegation");
nation=nation.trim();
String gg = new String(nation.getBytes("iso-8859-1"),"gb2312");
String file = "";
switch(gg)
{
case ("中国") : file="chn"; break; case ("法国") : file="french"; break;
case ("德国") : file="germany"; break;
default : out.println("error");
}
但是好像不行,怎么能实现这个功能呢???不会case不能以字符串为判断依据吧~~谢谢
解决方案 »
- jackrabbit 從filesystem 轉為 oraclefilesystem後,有什麼table和變化。
- 今天去面试了。考完理论又考了个上机题,题目是这样的
- 如何建立Dynamic web project并配置?
- 类似于126邮箱的那种很灵活的web界面结构,是用什么怎样开发的?
- 高分--------------如何根据字符串出现的次数获得其所在的位置????????????
- 有人知道jive的源代码再那下载吗???
- 请教关于JavaBean的问题?
- 无意发现一个servlet问题,百思不得其解,怪哉...怪哉...怪哉...
- jsp中文参数问题
- 当关闭浏览器时JSP如何能知道,使自已能作存盘的提示或动作,及清除写在数据库中的session?
- struts2+hibernate的数据库连接
- 如何解读源码
的确不能用字符串作为判断条件,
如一楼所说只接收int,byte,char,short条件
case "中国":
.
.
.
}
就是把括号去了再试试
引用链接:http://java.sun.com/docs/books/tutorial/java/nutsandbolts/switch.html
public static final java.util.Map<String, Integer> DELEGATION=new java.util.HashMap<String,Integer>();
static{
DELEGATION.put("中国", new Integer(1));
DELEGATION.put("法国", new Integer(2));
DELEGATION.put("德国", new Integer(3));
}
程序中写:
String nation=request.getParameter("delegation");
nation=nation.trim();
String gg = new String(nation.getBytes("iso-8859-1"),"gb2312");
String file = "";
int code=DELEGATION.get(gg);
switch(code)
{
case 1 : file="chn"; break;case 2 : file="french"; break;case 3 : file="germany"; break;default : out.println("error");
}