Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

structure, path to a servlet

 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
S Vilish
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should a xml file called web.xml where servelet mapping tag will be mentioned. Check in WEB-INF folder.
 
Urs Waefler
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic