you have to identify your context somehow so that it knows which context you want, so you need a real path to specify it. Within each context I create a virtual directory(servlet mapping) so that I can specify any filename in the directory and it will always go to my servlet. This works great for dynamic pages where the page name is sent to the database for retrieval, but it also works for cases where a servlet uses performs a couple of related tasks. This way your pagename idenitifes your task.
Charlie > -----Original Message----- > From: Noah Davis [mailto:[EMAIL PROTECTED]] > Sent: Sunday, November 17, 2002 2:58 AM > To: Tomcat Users List > Subject: Re: proper use of servlet contexts > > > Any other thoughts on this? Someone suggested using Struts . > . but short of > instituting a framework . . > > ----- Original Message ----- > From: "Noah Davis" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, November 12, 2002 8:18 PM > Subject: proper use of servlet contexts > > > 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 > > > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
