Sure it is. I am not sure if its possible in Servlet 2.1/2.2 to "path map"
to a specific controller servlet, but I think it is. I use extension mapping
myself. But basically you would do something in your web.xml file like:

<servlet>
  <servlet-name>controller</servlet-name>
  <display-name>controller</display-name>
  <servlet-class>com.mvc.servlets.ControllerServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>controller</servlet-name>
  <url-pattern>/ss/</url-pattern>
</servlet-mapping>

Now, anytime the /ss/ appears in the request path, it should pass everything
after the /ss/ as path info to the controller servlet its mapped to. Thus,
anytime the /ss/ is in your path, the servlet you map it to is invoked, and
I think the request.getPathInfo() or one of those calls returns everyting
after the /ss/. Therefore, a link like:

<a href="/web-app-context/ss/DoThis">Click</a>

Should call your servlet, and you would recieve a DoThis as a String
parameter or something.

Once you have that, you call upon your EJB session bean (or some business
logic class) that looks up in the database and returns you a path to go to.
Then you simply do:

try
{
  request.getRequestDispatcher(url-from-database).forward(request,response);
}
catch(Exception e)
{
}

That will forward you to the new URL.

Ask if you have any questions..but that should help a bit I hope.


> Hi everyone,
>
> Since it seems that the list is alive and well, although with very
> little traffic, I would like to ask a question which has been bothering
> me for a while.
>
> I am trying to do what I would define as dynamic redirection. What that
> means is that if someone writes an URL like http://myserver/name, I
> would like to look for "name" in a database and redirect the user to
> some other URL. This would allow me to avoid modifying manually the
> configuration file every time a mapping is added,removed or modified.
>
> Is this possible? Any suggestions?
>
> Thanks in advance and Happy New Year!
>
> Huibert Aalbers
>


Reply via email to