Professional Documents
Culture Documents
Example 2
Example 2
Example 2
"
This servlet prints a simple hello world. Note that the book has an interesting
history on the first documented "Hello World!" program.
o Try it
o Try it (using the "hi" alias)
o Try it (using the "/hello.html" alias)
o Try it (using the "/hello/*" alias)
o Try it (using the "*.hello" alias)
o Source
o web.xml Deployment Descriptor
Web.Xml(Deployment Descriptor)
- <web-app>
- <servlet>
<servlet-name>hi</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>/hello.html</url-pattern>
</servlet-mapping>
- <servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>*.hello</url-pattern>
</servlet-mapping>
- <servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>
Example 2.3: A servlet that knows to whom it's saying hello, modified to return
quickly in response to HEAD requests
This servlet uses the request's getMethod() method to improve performance
by detecting HEAD requests in the doGet() method so that it can return early.
o Try it
o Source