public void demo()
{
if (action.equals("single"))
{
if (version!=null && version.length()>0)
{
try{
Integer.parseInt(version);
ver=version;
}catch(Exception e)
{
out.println(config.pagemessage("back", "", "<font color=\"red\">版本信息错误!请输入正确的版本!</font>", 5000));
return;
}
}
if (connection!=null && connection.length()>0)
{
try{
number=Integer.parseInt(connection);
}catch(Exception e)
{
out.println(config.pagemessage("back", "", "<font color=\"red\">最小连接数错误!请输入正确的连接数!</font>", 5000));
return;
}
}
}
}public void demo()
{
checkVersion();
checkConnection();
}

解决方案 »

  1.   

    if 里的二个if可以方不过这二个if里操作这没简单是不是没这必要
      

  2.   

    嗯 可以看成就一个try....catch 
    关键是如何 return
      

  3.   

    checkvarsion:if (action.equals("single")&&version!=null && version.length()>0)
            {
                try{
                    Integer.parseInt(version);
                    ver=version;
                }catch(Exception e)
                {
                    out.println(config.pagemessage("back", "", "<font color=\"red\">版本信息错误!请输入正确的版本!</font>", 5000));
                    return;
                }
            }checkConnection:
    if (action.equals("single") && connection!=null && connection.length()>0)
            {
                try{
                    number=Integer.parseInt(connection);
                }catch(Exception e)
                {
                    out.println(config.pagemessage("back", "", "<font color=\"red\">最小连接数错误!请输入正确的连接数!</font>", 5000));
                    return;
                }
            }
      

  4.   

    public void demo()
    {
    if (action.equals("single"))
        {
         try{
           a();
           b();
         }catch(Exception e)
                {
                    out.println(config.pagemessage("back", e.getMessage(),5000));
                    return;
                }
         }
    }
    private int a(String version){
    if (version!=null && version.length()>0)
            {
                try{
                   ver= Integer.parseInt(version);
                }catch(Exception e)
                {
    throw new NullPointerException("<font color=\"red\">版本信息错误!请输入正确的版本!</font>");
                }
            }
    return ver;}private int b(String connection)throws Exception{
             if (connection!=null && connection.length()>0)
            {
                try{
                    number=Integer.parseInt(connection);
                }catch(Exception e)
                {
                    throw new NullPointerException("<font color=\"red\">最小连接数错误!请输入正确的连接数!</font>");
                                }
            }
    return number;
    }
      

  5.   

    throw new NullPointerException 这改成Exception 写错了
    a没throws Exception
      

  6.   

    try{
           a();
           b();
         }catch(Exception e)
                {
                    out.println(config.pagemessage("back", e.getMessage(),5000));
                    return;
                }没传值的...