Saturday, November 19, 2011

Case Sensative Database Query

Normally, the information kept in a cell of a database is not case sensative. For the query as below


Select * from tblShopInfo where shopName='bata'
Select * from tblShopInfo where shopName='batA'
Select * from tblShopInfo where shopName='Bata'



we will get same results for the all of the above queries. But if we are in need to get the information of case sensative partameter. Then we need to make the query as below:


Select * from tblShopInfo where shopName COLLATE Latin1_General_CS_AS ='baTa'



The above query will return only the specific info we need.

Tuesday, November 8, 2011

Request, Response, getParameter, getAttribute

All the above four terms are not so difficult. But for me sometimes they create a jam in my brain. To solve this jam..

Request : From Client to Server
Response: From Server to Client
Server: Receive Request and Send Response
Client: Send Request and Receive Response


Now,about getParameter()

when we submit a form they all the info is send to action element(resource) of the form. On the context of action element if we want to get the information of the submitted form, we should use

request.getParamater()

So request.getParameter() will retrieve a value that the client has submitted. You will get the value on the server side.

request.getAttribute(), this is all done server side. YOU add the attribute to the request and YOU submit the request to another resource, the client does not know about this. So all the code handling this would typically be in servlets.

Difference between sendRedirect and forward

sendRedirect is the marriage which is leagal as both the parties know each other and faithful.
forward: where one of the party cheats and contacts to third party.. a illicit relationship..

Probably this will make a clear concept to us, as all time we like to thinks in different way.

So, from the above we are sure about the family where Hubby and wife don't hide anything from each other. They share to each others every thing. Suppose, coming back from office, Husband request to make a cup of tea to his lovely wife. Wife is busy with her favorite TV serials. So, she tells the maid servant to mak the tea for him. Beside this Wife also inform his hubby about the maker of the tea and request to get tea from the servant. Then hubby will take the update of the tea from the servant.

On the contrary, in another family getting the request of tea from the husband, wife asked to make tea another one but after completion she must provide the tea directly to his wife.

First Family is sendRedirect and the second one is forward.

sendRedirect() sends a redirect response back to the client's browser. The browser will normally interpret this response by initiating a new request to the redirect URL given in the response.

forward() does not involve the client's browser. It just takes browser's current request, and hands it off to another servlet/jsp to handle. The client doesn't know that they're request is being handled by a different servlet/jsp than they originally called.

Sendredirect( ) : javax.Servlet.Http.HttpServletResponce interface
- RequestDispatcher.SendRedirect( ) works on the browser.
- The SendRedirect( ) allows you to redirect trip to the Client.
- The SendRedirect( ) allows you to redirect to any URL.
- After executing the SendRedirect( ) the control will not return back to same method.
- The Client receives the Http response code 302 indicating that temporarly the client is being redirected to the specified location , if the specified location is relative , this method converts it into an absolute URL before redirecting.
- The SendRedirect( ) will come to the Client and go back,.. ie URL appending will happen.





Forward( ) : javax.Servlet.RequestDispatcher interface.

- RequestDispatcher.forward( ) works on the Server.
- The forward( ) works inside the WebContainer.
- The forward( ) restricts you to redirect only to a resource in the same web-Application.
- After executing the forward( ), the control will return back to the same method from where the forward method was called.
- The forward( ) will redirect in the application server itself, it doesn't come back to the client.
- The forward( ) is faster than Sendredirect( ) .