製作一個網站在JSP上蝕:如果其他在JSP(開關殼體)
選擇[i]的從先前網頁獲取正確從1至5
一個串中的每個數字代表一個對象即:如果選擇[i] == 1那麼sub =數學
我不能切換大小寫的字符串,所以我試過如果其他..但子總是等於空(聲明)?我怎麼能讓子採取在條件的價值?
for (int i = 0; i < select.length; i++)
{
////
String sub=null;
if(select[i]=="1") {sub="Maths";}
else if (select[i]=="2") {sub="English";}
else if (select[i]=="3") {sub="Physics";}
else if (select[i]=="4") {sub="MI";}
else if (select[i]=="5") {sub="Software";}
////
rs=stmt.executeQuery("SELECT * FROM attends where userid= '"+user_id+"' and cid= '"+select[i]+"' ");
if(rs.next())//can not take it
{
out.println("You can not enroll in '"+sub+"' ");
}
else//can take it
{
int countUpdated =stmt.executeUpdate("INSERT INTO enroll (userid, cid) values ('"+user_id+"', '"+select[i]+"')");
out.println("Successfully enrolled in '"+sub+"' ");
}
}
如果其他條件正確..謝謝 – CodeX