【发布时间】:2009-10-10 11:13:46
【问题描述】:
我目前正在开发一个用于工资单的 Web 应用程序项目。这个网站是公开的。我想使用 jquery + ajax 以服务器端 lang 作为 jsp 来实现某些功能。有哪些指南有助于编写成熟、安全的代码。
【问题讨论】:
我目前正在开发一个用于工资单的 Web 应用程序项目。这个网站是公开的。我想使用 jquery + ajax 以服务器端 lang 作为 jsp 来实现某些功能。有哪些指南有助于编写成熟、安全的代码。
【问题讨论】:
第 1 课
清理您的输入
您可以通过在表单等上引入客户端验证来使它变得漂亮,但决不能依赖它来为您的 JSP 提供干净的数据。您的 JSP 需要将收到的所有数据与已知的良好输入进行匹配。如果任何输入与预期输入匹配,则应抛出一般错误。
这一点我怎么强调都不过分,尤其是对于工资单软件。
【讨论】:
在白板上写字。
I promise to sanitize,filter and validate my data before any changes are made.
I promise to sanitize,filter and validate my data before any changes are made.
I promise to sanitize,filter and validate my data before any changes are made.
I promise to sanitize,filter and validate my data before any changes are made.
I promise to sanitize,filter and validate my data before any changes are made.
I promise to sanitize,filter and validate my data before any changes are made.
那么现在。
在编写这样的系统时,您需要保持代码抽象,不要只为每个操作编写一个函数,示例
不要这样做。
function updateEmailAddress(id,email)
{
$.post("ajax/updateEmail.php",{id:id,email:email});
}
updateEmailAddress(22,'some_new_email@mydomain.tld');
这样做,构建一个可重用代码的系统。
System = {
Send : function(location,method,data,callback)
{
//Send here to location via method with data and then invoke the callback
}
}
Actions = {
UpdateMail(id,mail)
{
System.Send('ajax/mailupdate.php','post',{id:id,email:mail},function(data){
//Validate Server Responce
});
}
CheckLoginState(callback)
{
System.Send('ajax/loginState.php','post',{},function(data){
callback(data ? true : false);
});
}
//ETC
//ETC
}
Action.CheckLoginState(function(loggedin){
if(loggedin){
Action.UpdateMail(someId,SomeEmail);
}
});
【讨论】: