I have a question regarding the proper way to use servlet contexts. The way I've been using them I always seem to bump into one problem or another which affects the flexibility of using servlets or affects the portability of my application.
Here's my problem: I developed several servlets and defined them in the web.xml file. Then I referenced them in a form as such: <form action="/<context>/doThis" method="post"> Now I've made my application dependent on my servlet context. Ok, so I decided that instead of referencing my servlets in a root (context) relative way I would reference them in a relative way from the page i'm on: <form action="doThis" method="post"> I would then map the servlet in a way that parallels my physical directory structure. If the form tag above was on a page "/help/finance/index.jsp", I would have to map the above servlet as "/help/finance/doThis", in order for it to resolve correctly. Ok, great. Now I have a way to refer to servlets that doesn't affect the portability of my application. But it's seems like this isn't a great solution either. What if I use this servlet in multiple places? Now I have to go back and add new mappings in each place to make sure that a relative call to this servlet works in these cases as well. Now I'm thinking that possibly the best solution is to prepend the servlet context for each form action call: <form action="<%=pageContext.getServletContext()%>doThis" method="post"> But this seems like a round about way to go for something so simple. Am I missing something here? A second issue is that if your servlet does a forward using the request dispatcher AND your servlet url mapping does not reflect your directory structure, all the image paths and links and such could get screwed. There is a workaround using the HTML Base tag, but this isn't an option in my particular situation. Thoughts on this? Thanks in advance. Noah
