wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes structure, path to a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "structure, path to a servlet" Watch "structure, path to a servlet" New topic
Author

structure, path to a servlet

Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
I study the famous book SCWCD from Davis Bridgewater. I am in Chapter 1. I did ex0102. Everything works fine. Although I do not understand, how the application knows the location of the servlet.

I starts like that.

http://localhost:8080/ex0102/weather.html

This is the entry form.

The source code of the entry form conatains this line:

<form action="Weather" method="post">

That means, by clicking the button submit it sends the data to the servlet Weather.

I only find a file like this (it is the corresponding servlet):

WeatherParams.class

I do not understand how it finds this servlet. Above one can only read action="Weather", but there is no URL?


SCJP 1.4
S Vilish
Ranch Hand

Joined: Feb 06, 2007
Posts: 39
There should a xml file called web.xml where servelet mapping tag will be mentioned. Check in WEB-INF folder.
Urs Waefler
Ranch Hand

Joined: Mar 13, 2007
Posts: 77
I found this:

<?xml version="1.0" ?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- <servlet>
<servlet-name>Weather</servlet-name>
<servlet-class>webcert.ch01.ex0102.WeatherParams</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>Weather</servlet-name>
<url-pattern>/Weather</url-pattern>
</servlet-mapping>
</web-app>

Am I right? But I do not properly understand it. Could you explain it?
S Vilish
Ranch Hand

Joined: Feb 06, 2007
Posts: 39
Well this point should be learned first when you are going to write your first servlet. A web server understand a web application and its element by its web.xml. For your info following is a brief explanation.

Look this ...

<servlet>
<servlet-name>Weather</servlet-name>
<servlet-class>webcert.ch01.ex0102.WeatherParams</servlet-class>
</servlet>
- <servlet-mapping>
<servlet-name>Weather</servlet-name>
<url-pattern>/Weather</url-pattern>
</servlet-mapping>

<Servlet-lass> has been assigned a new name <servlet-name> in the <servlet> tag and for that particular name is mapped in <servlet-mapping> tg to a <url-pattern> so all the url ending with that specific url will be handled by the mapped servlet. that's all.

For more info try google, search your book this explanation must be mentioed somewhere.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: structure, path to a servlet
 
Similar Threads
do not understand compiling a servlet
Servlet Mapping
Html POST & GET
Session Tracking across doPost() & doGet()
Servlet program not running