Re: Java/TomCat How to Configure a Servlet contextPath



Rich Morey <richard.morey@xxxxxxxxx> said:
I should say that I am just learning Java & Tomcat at this point. My
web development experience prior to this was with Delphi. When
building a Delphi web app a URL would look something like this:

http://host/library.dll/action?

In this case, the "library.dll" file could/would contain multiple
"actions" that could be invoked like this:

http://host/library.dll/action1?
http://host/library.dll/action2?

Yep. As Owen already wrote, you should consider your web application
(whether packaged as a .war file, or whether just deployed as an open
directory) as a concept similar to your library.dll on Delphi side.

Then write servlets for your distinct actions, and you have exactly
the same calling structure. If you have actions that very much share
the same code, you could consider making two servlet-mappings for
a single servlet in your web.xml -- that is, have a single servlet
available via two action names, and check in the servlet which name
was used to call it. Or of course, you can use inheritance or
encapsulation as in normal Java code, and have either one of the
servlets extend the other, or have a third, possibly a non-servlet
class, from which the two servlets can access the common functionality.

You can also, if you want, map a branch of your HTTP resource tree
to a single servlet, with a servlet-mapping like this:
<servlet-mapping>
<servlet-name>Controller</servlet-name>
<url-pattern>/Controller/*</url-pattern>
</servlet-mapping>

Now, http://server:port/context/Controller/whatever/path/here?with=params
will be processed by the servlet named "Controller" (mind you, this name
does not need to bear any relation to the servlet class name).

Then, of course, you could also call your servlet like
http://server:port/context/Controller?action=someaction&other=params
and have your servlet branch the processing based on the value of the
"action" parameter.

So, there are a number of ways to provide the processing functionality
you're looking for. I'd favor the one recommended by Owen, that is,
switch your thinking so that you consider the web-app as the .dll
equivalent, and servlets as your actions. Have the servlets
interpret the parameters, feed the data into appropriate backend classes,
and set up the result data ready to request context, and forward
the request to the proper .jsp file for viewing the results to
the end user. So, you'll have a model (backend classes), view
(the .jsp file) and a controller (the servlet).
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
.



Relevant Pages

  • RequestDispatcher and relative locations
    ... was forwarded a ServletRequest using RequestDispatcher from a servlet? ... define a simple jsp file: ... this css file never gets loaded using forwarding (FOOBAR ...
    (comp.lang.java.programmer)
  • Re: Include a Servlet into web page body
    ... > html menu and a table cell where i need to include a servlet call result. ... > Servlet is called with the same parameters as the .jsp file. ...
    (comp.lang.java)
  • Re: Include a Servlet into web page body
    ... > html menu and a table cell where i need to include a servlet call result. ... > Servlet is called with the same parameters as the .jsp file. ...
    (comp.lang.java.programmer)
  • Re: Include a Servlet into web page body
    ... Luis. ... > html menu and a table cell where i need to include a servlet call result. ... > Servlet is called with the same parameters as the .jsp file. ...
    (comp.lang.java.programmer)
  • Re: Include a Servlet into web page body
    ... Luis. ... > html menu and a table cell where i need to include a servlet call result. ... > Servlet is called with the same parameters as the .jsp file. ...
    (comp.lang.java)