博文

目前显示的是 五月, 2013的博文

Web application design pattern - prevent duplicated form submission

图片
这是一个web development中常见的问题。User经常会迫不及待的点击submit按钮很多次,这样便会submit很多requests到服务器,然后出现各种问题。 解决方法有很多: 在客户端使用javascript来disable submit button以防用户多次点击。 使用Post/Redirect/Get pattern来防止用户使用F5或者Back按钮产生的muliple submittion. 如果不使用Post/Redirect/Get pattern就像这样: 使用Post/Redirect/Get pattern就是这样: 在生成页面时在server产生一个token,然后把这个token放在页面的hidden field 里面,当submit这个form时同时发送这个token回到server进行验证,如果server有这个token就成功process然后remove这个token,如果server没有这个token就停止process.(这说明这个form已经被submit过了) 可是使用来产生token的方法比如 java.util.UUID 或者apache的RandomStringUitls.

Understand the index in database tables/views/columns

Index的定义: An index is an on-disk structure associated with a table or view that speeds up retrieval of rows from the table or view. Index的类型可以有很多种: UNIQUE - A unique index is one in which no two rows are permitted to have the same index key value. CLUSTERED - Creates an index in which the logical order of the key values determines the physical order of the corresponding rows in a table. NONCLUSTERED - Creates an index that specifies the logical ordering of a table. With a nonclustered index, the physical order of the data rows is independent of their indexed order. 为了立即上面这些不同类型的Index首先我们要看一下table的存储方式。 "A heap is a table without a clustered index." 当一个table没有clustered index时, 这个table的rows就不会以sorted/ordered方式存储在disk.这就意味着,如果这个table连non-clustered的index也没有时,如果我们想要找出其中一个column的一个value, 它就需要遍历整个table了。 所以这就是clustered index的作用,同时也是为什么clustered index对每个table只能有一个。 那么什么是non-clustered的index呢? "Nonclustered indexes have a structure separate from the data rows. A no...