• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

structure, path to a servlet

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic