Monday, June 8, 2009

SCWCD Notes - Web App Deployment

Tag Files- Must be deployed in WEB-INF/tags folder or subfolder. In case of jar it should be in META-INF/tags folder or subfolder.
If tag file is put anywhere else the container will recognise it as a static content.

Library Dependencies - In WAR file, META-INF/MANIFEST.MF is used to declare the library dependencies. It gives the deploy-time check for whether the container can find the packages and classes our app depends on.
Even if we dont put the META-INF directory in WAR, after deployment when the WAR is exploded, then META-INF and MANIFEST.MF is created inside that.

Server returns 404 Page not found error, if anything inside META-INF or WEB-INF is requested by client. But we can keep here active contents which can be included or forwarded by other jsp page, but client cannot request them directly.

Container will always looks for classes in WEB-INF/classes directry then it will go to WEB-INF/lib directory for jars.

classloader's getResource() and getResourceAsStream() methods can be used to access a resource (text file, JPEG etc) that's also inside a JAR. These methods are also inServletContext, but they work only for the resources which are not deployed in the jar file.

Servlet Mapping - <servlet-name>is mapped to <url-pattern>. <servlet-name>is the key and every request is come to <url-pattern>which picks the servlet associated with <servlet-name>
Three types of url pattern are their. The container looks for the matches in the given below order of match-pattern. First it chooses exact match, if its not found then opts for directory match and after al last it goes for extension match.

  1. Exact Match: Must begin with slash(/), may have an extension but not mandatory. e.g.<url-pattern>/beer/
  2. Directory Match: Must begin with an slash(/). The directory can be real or virtual. It ends with slash(/) or *. e.g. <url-pattern>/beer/*.
  3. Extension Match: Must begin with an * (never with slash) . After the * it must have an dot(.) extension. e.g. <url-pattern>*.do.

Lastly the most specific match wins. for example request for /foo/bar/ will also matc /foo/bar/* and /foo/*. But the first one will be selected because its more specific to the request.

Configuring Welcome files in DD: welcome files are default page, they appear when only name of website is given in URL without specifying any URL. For example entering <a href=""></a> will take to yahoo home page, here home page is welcome file of the yahoo web application.

The files in the <welcome-file>do not start with a slash. Multiple welcome files <welcome-file>go in a single DD element <welcome-file-list>.<welcome-file-list>
<welcome-file>index.html </welcome-file>
<welcome-file>deault.jsp </welcome-file>

Now if the web-app is having diffenerent direcotries, we don't need to specify default html or jsp pages for them separately. All default pages will be specified in on place in <welcome-file-list>and container will choose first page matching to the request. For every request container first looks for servlet url mapping, if iti doesnot finds any match then opts to scan <welcome-file-list>


Request: <a href="http://localhost:8080/MyTestApp/">http://localhost:8080/MyTestApp/</a>
Container: Choice: MyTestApp/index.html
Request: <a href="http://localhost:8080/MyTestApp/registation">http://localhost:8080/MyTestApp/registation</a>
Container: Choice: MyTestApp/registration/index.html
Request: <a href="http://localhost:8080/MyTestApp/search">http://localhost:8080/MyTestApp/search</a>
Container: Choice: MyTestApp/search/default.jsp(if index.html and default.jsp both would be in search direcotry then container will take index.html)
Request: <a href="http://localhost:8080/registration/newMember">http://localhost:8080/registration/newMember</a>
Container: Choice: When no files from <welcome-file-list>is specified the behaviou r vendor specific. Tomcat shows directory list, another container may shoe 404 error.

Configuring Error Pages in DD: Used to display freindly message when any error/exception happens.

catch-all error page: applies to everything in web app- not just in jsps. Anything thatsThrowable can be declared in <exception-type>
(this can be overridden in original jsp by adding a page directive with an errorPage attribute)
Explicit exception error page: for example, follwing error page will be called only when there's ArithmeticExcption, for all other exceptions te first error page will be called (Throwable)
HTTP statuc code error page: for example, following error page will come when the status code for the response is 404. HttpServletResponse.sendError(402) can also be used to send own response code and pull the pages from <error-page> tag.
response.sendError(HttpServletresponse.SC_FORBIDDEN); and response.sendError(403); are same.

Note: We cannot have both status code and exception type in single <error-page>tag.

</web-app>Configuring Servlet initialization in DD: Servlets are initialized at first request. So when the first client requests a servlet, class loading, instantiation and initalization happens of a servlet, before service() method can be invoked.

To load servlet on deploy time <load-on-startup> element is used in DD.



Now the servelt one will be loaded first then servlet two will be loaded durig deployment. Any number greater than zero in <load-on-startup> element assists the servlet to be initailized during deployment.

Writing XML compilant JSP:

  1. <%@page import="java.util.*" %> --- < import="java.util.*" />
  2. <%! int y=3; %> ---- <jsp:declaration>int y=3;</jsp:declaration>
  3. <% list.add("Hoop"); > ---- <jsp:scriptlet>list.add("Hoop");</jsp:scriptlet>
  4. There is no spoon ---- <jsp:text>There is no spoon</jsp:text>
  5. <= %> ---- <jsp:expression> </jsp:expression >

Refering EJBs in web-app:

Local Beans : <ejb-local-ref>

Remote Beans :<ejb-ref>

Env Entry: <env-entry>

<env-entry-name>- This will be used in code to lookup entry.
<env-entry-type>- It can be any type that takes a single String as a constructor parameter or a single character if the type is java.lang.Character.
<env-entry-value>- It will be passed in as String or a single character if the is java.lang.Character.

Note that its not only primitive type or wrapper type. It can be any type which have single String as parameter constructor.

Configuring Mime type mapping: mapping between extension and the mime type.

<extension>mpg</extension> <!-- do not include the dot "." -->

No comments:

Post a Comment

Amazon Best Sellors

Weblogic - Server Creation - Issues

Datasource creation using python script.  Python Script was failing after creating Datasource. From UI Admin Console, if I try to activat...