J2ee Odp
J2ee Odp
Content
1)Better performance:
Because it creates a thread for each request
not process (like CGI).
2)Platform independent:
Because it uses java language and java is
robust language.
3)Trusted
4)Library:
Full functionality of java library is available.
Servlet Api
1)javax.servlet
2)javax.servlet.http
javax.servlet
Interfaces Classes
1)HttpServlet
1)HttpServletRequest
2)Cookie
2)HttpServletResponse 3)HttpServletRequestWrapper
3)HttpSession 4)HttpServletResponseWrapp
er
4)HttpSessionListener
Servlet Hierarchy
Environment Setup
Generic HttpServlet
1)Generic Servlet is 1)Specially designed
protocol Independent. for Http protocol.
(http,smtp,ftp)
2)Supports all http
2)Service method methods.
handles all request
3)Can handle session
3)Can handle only & cookie data
simple requests
4)can’t handle session
data
HttpServletRequest Methods
GetPrameterValues( ) - String[ ]
getParametetNames( ) : Returns an
Enumeration of String.
(returns null if not any parameter found)
Example to handle Query Data
Get Post
1) Data is sent in Url. 1) Data is sent in request body.
2) Get request is not secured 2) Post request is secured
because data is exposed in because data is not exposed
URL. in URL.
3) Get request can be 3) Post request cannot be
bookmarked and is more bookmarked.
efficient.
4) Get request can send only 4) Large amount of data can be
limited amount of data sent.
around 2048 characters
Response Type
<web-app>
<servlet>
<servlet-name>alias name</servlet-name>
<servlet-class>fully qualified class name</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>alias name</servlet-name>
<url-pattern>/url pattern</url-pattern>
</servlet-mapping>
</web-app>
Welcome File list
<web-app>
....
<welcome-file-list>
<welcome-file>home.html</welcome-file>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
</web-app>
Servlet Exception Handling
<error-page>
<exception-type>Exception Class Path
</exception-type>
<location>/Servlet or HTML</location>
</error-page>
Exception Points to Remember
In web.xml
Methods of ServletConfig interface
<context-param>
<param-name>parametername</param-
name>
<param-value>parametervalue</param-value>
</context-param>
......
</web-app>
Difference Between ServletContext and
ServletConfig
http://bit.do/contextAndConfig