Head first Servlets and Jsp Chapter 11 Short Notes

May 25, 2011 at 6:11 pm Leave a comment

Note: Feel free to copy the post, modify and comment
Deploying your webapp

Objectives:
* Deployment directory structure
* Describe purpose and semantics of error-page, init-param, mime-mapping, servlet, servlet-class, servlet-mapping, servlet-name and welcome-file
* Explain structure and purpose of WAR file
* Write a jsp language with xml based syntax

1. Need to consider 3 things to understand the deployed app

1. Where to put the files and directories
2. Where will the container look for things in webapp
3. How does the client request things in web app

Building directory structure for the following
* TLDs, Tags, web.xml, static-htmls, Jsps, Classes, jars etc..,

2. WAR File
* In tomcat, the name of the WAR file becomes the webapp name
* META-INF/MANIFEST.MF where you can declare the WAR library dependencies so that container can check at runtime instead of blowing up with application runs

3. Making JSPs and static htmls accessible
* Can prevent direct access by placing the files under WEB-INF or META-INF (in case of war file). And will return 404 on error

4. Configuring welcome-file
<web-app>
	<welcome-file-list>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
	</welcome-file-list>
</web-app>
* no slash allowed in beginning or end

5. Error pages in DD

<error-page>
	<exception-type>java.lang.throwable</exception-type>
	<location>/errorpage.jsp</location>
</error-page>

<error-page>
	<error-code>404</error-code>
	<location>/notFoundpage.jsp</location>
</error-page>

or

response.sendError(HttPServletResponse.SC_FORBIDDEN);

6. Configuring Servlet initialization

<servlet>
	<servlet-name>....
	<load-on-startup>1</load-on-startup>
</servlet>

Any number > 0 can be used
The number says the order of startup. For same values, its loaded as per the order of appearance in DD

7. XML Compliant JSP

directive: <jsp:directive.page import=""/>
declaration: <jsp:declaration>int a = 3;
scriplet: list.add("")
text: <jsp:text>this is a text
Scription expression: aVariable

8. EJB Related Deployment descriptor

Local reference:

<ejb-local-ref>
	<ejb-ref-name></ejb-ref-name>
	<ejb-ref-type>Entity</ejb-ref-type>
	<local-home></local-home>
	<local></local>
</ejb-local-ref>

Remote Reference:

<ejb-ref>
	<ejb-ref-name></ejb-ref-name>
	<ejb-ref-type>Entity</ejb-ref-type>
	<home></home>
	<remote></remote>
</ejb-ref>

9. Memorizing the JNDI  DD tag

<env-entry>
	rates/discountRate
	<env-entry-type>java.lang.Integer
	<env-entry-value>10
</env-entry>

* Env entry cannot be primitive and can declare any type which can take string as an arg in constructor
* And this works only if you have a fully j2ee compliant server and not just web container

10. Mime mapping

<mime-mapping>
	<extension>mympg</extension>
	<mime-type>video/mpeg</mime-type>
</mime-mapping>
Advertisement

Entry filed under: Education, programming, web. Tags: .

Head first Servlets and Jsp Chapter 10 Short Notes Head first Servlets and Jsp Chapter 12 Short Notes

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed



Follow

Get every new post delivered to your Inbox.