• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question about servlet-mapping and auto redirecting URL

 
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an old servlet application which used old servlet API. The URL was like : http://server/servlet/MyServlet . Now I upgraded the server and reorganized the file struture so the new URL is : http://server/myapp/servlet/MyServlet, in which I created an application called "myapp" and put all .class in myapp/WEB-INF/classes/.

Now I want the old link to be automatically redirected to the new link. I want to use <servlet-mapping> and here is how I tried --
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>Myservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/servlet/MyServlet</url-pattern>
</servlet-mapping>

But it does NOT work. Can somebody help ?
Thanks.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank,
I think you need to deploy a separate web app that does not have myapp as a context root. It would have one servlet that redirects all requests to the URL.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Frank Sikuluzu:

<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>Myservlet</servlet-class>
</servlet>



Frank, you are not misspelling MyServlet as Myservlet by any chance, are you?
You may want to post more details of what 'does not work' in this case mean. For example, whether you get a 404 error or some other exception or a blank page or whatever.
 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first of all, there is no misspelling problem although I might make some typo here. Secondly the error msg was "File Not found". Now I guess I know what's going on --- Since this web.xml is contained in this "myapp", there is no way that I can map the "/myapp/servlet/MyServlet" to "/servlet/MyServlet", right ?

Another question is -- if the URL is like http://server/myapp/servlet/MyServlet?param=abc, then how to redirect ? (This case how to carry the "param=abc" ?)
 
reply
    Bookmark Topic Watch Topic
  • New Topic