| File
Structures for Servlets Fall 2006, David Matuszek |
| These are notes that I made for myself, while getting assorted servlets to work. I'm posting it for whatever value it might have. |
Where there are numbered options, the numbers in each section must correspond.
Note: The http://192.168.1.152 links are not functional; they are links to actual servlets on my own hard drive, not to a public server.
| A simple servlet | |
|---|---|
| URL | http://192.168.1.152/ch1/Serv1 |
| Description | Servlet that displays the current time. |
| File structure |
|
| package | none |
| servlet-class | Ch1Servlet |
| url-pattern | /Serv1 |
| JSP only | |
|---|---|
| URL | http://192.168.1.152/Hello.jsp |
| Description | JSP only page; WEB-INF folder must be present |
| File structure |
|
| web.xml | none |
| A packaged servlet that uses JSP | |
|---|---|
| URL | http://192.168.1.152/Beer-v1/form.html |
| Description | Beer HTML page calls BeerExpert to compute results. |
| File structure |
|
| package |
com.example.model |
| servlet-class | com.example.web.BeerSelect |
| url-pattern | /SelectBeer.do |
| A servlet that opens a dialog on the server (!) | |
|---|---|
| URL |
|
| Description |
Servlet opens an input dialog and sends the inputted text back in an HTML page. All newlines are lost, however. Observation: The URL is the path structure, skipping over |
| File structure |
|
| package | none |
| servlet-class | SendText |
| url-pattern |
|
| A servlet that returns a jar file | |
|---|---|
| URL | http://192.168.1.152/JarDownload/form.html |
| Description | HTML page has a link to http://192.168.1.152/JarDownload/FunWithPanels.jar |
| File structure |
|
| package | none |
| servlet-class | CodeReturn |
| url-pattern | /FunWithPanels.jar |
You always need a WEB-INF folder, even if it's empty.
If the package declaration says
package x.y.z;
then the file structure is
webapps - projectName - WEB-INF - classes
- x - y - z - MyCode.class
and the servlet-class is
x.y.z.MyCode
and the url-pattern is
/whatever
then we need the URL
http://localhost/whatever/