Question 1: Where does the web.xml fit into things (when is it used/called, and where is it called from)?
What does the above snippet do (or, what does it cause to happen)? At
some point in my web app qrst.jsp gets used; is it the
DispatcherServlet that calls qrst.jsp using the servlet name? Else what
is the significance of the servlet name? What is load on startup?
Links or explanation of what the above does? I can see from looking
at the XML file that it contains bean definitions and I do understand
what beans are and how they are used, but I don't know any other details
about this and would like to.
Servlets are JavaEE's idiom for answering
HTTP requests. You program the behavior of your application in a Servlet which will respond to a request.
Tomcat is a Servlet container, which means you deploy your
application in Tomcat and it will manage all the communication
infrastructure for you: it accepts connections, manages database
connections(*) and will call upon your servlets to handle incoming
requests.
web.xml
is part of any JavaEE application, not Spring. Your code sample 1 declares that your app will use an instance of class
org.springframework.web.servlet.DispatcherServlet
to handle incoming requests.
Although servlets are the basic foundations for JavaEE development,
it is not advised to create your own; instead, with Spring, you create
MVC controllers.
Then the DispatcherServlet will call upon these controllers to handle
the requests. It's just another indirection (but a very powerful one!)
is it the DispatcherServlet that calls qrst.jsp using the servlet name?
Not directly. It's just a coincidence that your servlet and the JSP file have the same name.
What is loaded on startup?
Your code sample 2 instructs the DispatcherServlet to load the beans from file
/someLocation/some-servlet.xml
. If there are
controller beans in this file and according to how you configured the
url mapping, beans from this file will answer the incoming requests. See
the reference.
I believe those init-param elements are just parameters that get set in the servlet's java class
The init-param elements in web.xml are for the servlet class.
The web app somehow "knows" when an AJAX (dwr) call is happening
versus when the web app is being loaded for the first time (when its
loading for the first time it should use qrst.jsp). How does it know
this?
Missing from the question are either the
<servlet-mapping>
element (found in web.xml), or the url mappings (found in the spring
files). These are responsible for deciding whether an URL should be
handled by the dispatcher servlet or the dwr servlet.
For instance, with an servlet mapping like below:
<servlet-mapping>
<servlet-name>qsrt</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dwr</servlet-name>
<url-pattern>*.dwr</url-pattern>
</servlet-mapping>
Then all URLs ending in
.do
will be answered by the dispatcher servlet, and those ending with
.dwr
will be handled by the dwr servlet. Here's where the names of the servlets are important.
JSP files are a different story. The container will simply use them
to handle a URL ending in *.jsp. Do not create your onw servlet mapping
for URLs ending in
*.jsp
. This will only cause headaches. This is probably unspecified behavior.
Edit:
However, the URL in the browser's address bar always looks the same: it would always invoke the qrst servlet
Then it is possible that your servlet-mapping is so broad (something like:
<url-pattern>/*</url-pattern>
) that it will handle anything you throw at the server and never give a chance for the other servlets to handle it.
Last but not least, when working with DWR or any Ajax technology, install the
HttpFox extension for Firefox so you can monitor the Ajax calls of your application.