You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Immanuel, Gidado-Yisa" <av...@cdc.gov> on 2002/03/04 18:47:34 UTC

Prefix mapping versus Extension mapping

CURRENT STATE OF THE ART
Currently, if I use prefix mapping like this:

  <servlet-mapping>
    <servlet-name>controller</servlet-name>
    <url-pattern>/projects/*</url-pattern>
  </servlet-mapping>

Then when I go to 

  http://localhost/CONTEXT/projects/View

the url is broken down into:

  context path: /CONTEXT
  servlet path: /projects
  path info:    /View

which get's mapped to the action '/View'.

PROBLEMS
I'm running into 2 problems.  The first is that if I want
to define another path-mapping, for example '/admin', then
I have to do that in the web.xml (rather than struts-config)
which is counter intuitive.  (Multi-app support probably
makes this point moot...).

The second problem is that when using multiple paths, e.g.:

  /projects/*
  /admin/*

which go to the same ActionServlet, there is one namespace
for the actions, that is, '/projects/View' and '/admin/View'
map to the same action (namely, '/View').  It would be nice
if it were possible that when an action is named '/projects/View'
that the URL '/projects/View' would map to it (rather than
the current '/projects/projects/View').  Also, if this were
the case, then there would be a nice symmetry from naming
actions for prefix mapping as well as for extension mapping.

Would the changes be as simple as modifying the following
ActionServlet.processPath()?  Thoughts?

    protected String processPath(HttpServletRequest request) {

	String path = null;

	// For prefix matching, we want to match on the path info (if any)
        path =
            (String)
request.getAttribute("javax.servlet.include.path_info");
        if (path == null)
            path = request.getPathInfo();
	if ((path != null) && (path.length() > 0))
-	    return (path);
+         return (request.getServletPath() + path);

	// For extension matching, we want to strip the extension (if any)
        path =
           (String)
request.getAttribute("javax.servlet.include.servlet_path");
        if (path == null)
            path = request.getServletPath();
	int slash = path.lastIndexOf("/");
	int period = path.lastIndexOf(".");
	if ((period >= 0) && (period > slash))
	    path = path.substring(0, period);
	return (path);

    }

Thanks,
Gidado

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>