日期:2014-05-18  浏览次数:20724 次

Jsp语法错误在哪里?
if(project_id==null)
{
_sql1="select * from wip where Status='active' ";
}
else
{
out.println("project_id is " +project_id+"<br>");
if(project_id=="all")
{
_sql1="select * from wip";
out.println("this is all");
}
else
{
_sql1="select * from wip where ProName='"+project_id+"'";
}


当project_id是为all时,怎么不执行if(project_id=="all")呀?就直接到else了.我这哪有问题呀

------解决方案--------------------
请将 if(project_id=="all") //这句是判断变量project_id与"All"这两个对象的内存地址是否相同,一般情况下是不同的,所以不会执行
换成 if (project_id.equals("all")) //这句是判断project_id的值是否等于"all",它会执行

------解决方案--------------------
if ("all".equals(project_id)) {
...
} else {
...
}

将 "all" 放前面,可避免当 project_id == null 时, project_id.equals(...) 抛空指针异常