在花了多年时间构建java驱动的webapps之后,我转而使用PHP,对我来说,这种差异主要是因为要设置的东西要少得多,而且像PHP这样的语言都是松散类型的,这意味着你不必费劲地将东西转换成其他东西,代码行数行似乎有点过火。在
java示例://omitting the lines and lines of stuff to set up a request and
//the try catch and the exeptions that *might* get thrown
String numberInput = request.getAttribute('numberInput');
int result=0;
if (numberInput!=null && numberInput.length()>0)
{
result=Integer.parseInt(numberInput)+1;
//but now we need to wrap this in a try/catch to catch NFE exeptions
}
//can't just echo it, need to set up an output thingy... ommitting all that too
out.print(result);
out.flush();
out.close();
要使用PHP实现相同的功能:
^{pr2}$
这对我来说是最大的好处,因为在必须验证用户输入时,我总是对java感到沮丧。每次我都要做很多事情,每次输入,在PHP中都是不必要的。当然,验证仍然必须完成,在PHP中要容易得多。在
希望这有帮助。在