Servlets and JSP pages use cookies by default to manage sessions. A cookie is a set of values, a name-value pair, which is sent to a client. Cookie implementations usually involve files stored on the client machine, and the location of such files is browser dependent. It is important to remember that cookies can t be trusted to maintain sessions. For example, the client machine may have cookies disabled. In this situation, the servlet can use a technique called URL rewriting, which involves encoding the session key in the request URL. The servlet can decode the URL to extract the session key, thereby identifying the appropriate client belonging to that particular session. Encoding and Parsing Form Data Data sent with a get or post request may be encoded in a scheme known as URL encoding. The encoding replaces special characters, such as spaces and unprintable characters, with symbols and hex values. Names and values are encoded separately. You ve seen this encoding on search engines before. For example, an advanced search in the Google search engine (http://www.google.com/) encodes search parameters as follows: http://www.google.com/search?as_q=quantum+computing&num=10&btnG=Google+Search&as_oq=&as_epq=&as_eq=&as_occt=title&lr=&as_dt=i&sitesearch=&safe=off Notice the name-value pairs (q=quantum+computing) with the + symbol replacing the blank, the & symbol connecting multiple search criteria, and the setting of hidden parameters (safe=off). Servers are capable of automatically decoding this data. Whether the data is sent by a getrequest or post request, your JSP page can decode and retrieve the data by using the getParameter method of the request object. For example, the JSP expression shown below retrieves the value of the q parameter: <%= request.getParameter("q") %> Using the above method eliminates the necessity of writing code to parse the data or having to use the java.net.URLEncoder and java.net.URLDecoder classes. Accessing Shared Data JSPs and servlets may exchange data by using a set of methods available to objects of class ServletContext. In JSP lingo, the application scope represents objects derived from class ServletContext. Some of these methods are getAttribute, getAttributeNames, setAttribute, and removeAttribute. Servlets and JSPs also can share initialization parameters and configuration settings by using methods available to objects of class ServletConfig, such as getInitParameter and getInitParameterNames. Your Web server may have additional methods to expose various properties and attributes of your server environment to your JSP pages. Servlets provide the JSP programmer with powerful features that are accessed with standard JSP expressions. You may think that you ll never have to code a servlet because all your dynamic Web page content needs are addressed by JSP. Although JSP brings unparalleled abilities to the Web application developer, you shouldn t throw out that servlet API documentation just yet. The following section touches on some cases in which you may want to use Java servlets with your JSPs.
Do you have a godaddy domain name? If you do, you have found the right web hosting provider for you.Our Godaddy Web Hosting packages are the best match to well known, affordable godaddy domain names.

Leave a Reply