I find that the standard answer to shortening the path of using 
mod_rewrite rather Apache specific.  And I am surprised that no one on 
this list tries to address this issue through the Servlet 
specification.  I have researched this problem and found a solution 
within the specification to address this.  Unfortunately, the sample 
application does not support the web.xml definition that would allow the 
changed URI to take place.  I haven't had a chance to track down the 
problem to be within Flux or the Turbine toolkit itself though. 

The trick is understanding how the URI is broken out using the 
definition "requestURI = contextpath + servletpath + pathInfo" (page 29 
of 2.2 spec).  The contextpath is controlled by servlet container 
configuration,  the servletpath is determined by your web.xml definition 
for the servlet and your pathInfo is what follows the servletpath to be 
interpreted by the servlet itself and it is optional.  For the 
requestURI "/newapp/servlet/newapp" used by the Turbine examples, the 
path components are broken out as follows:

contextpath = /newapp  (This is the name of the directory in 
${TOMCAT_HOME}/webapps by default)
servletpath = /servlet/newapp
pathInfo = null

To shorten the request URI to /newapp for example, what you want to do 
is make the default servlet path of "/" to point to your newapp servlet 
instead (as defined in section 10.2 of the spec).  To get the newapp 
servlet to be your default servlet make the following addition to your 
web.xml file after all your servlet definitions. The web.xml DTD is 
rather specific as to the ordering of it elements, it just can't go 
anywhere.

  <servlet-mapping>
    <servlet-name>newapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

Once this is done, restart your server and you should find that you can 
get to the newapp servlet with the request URI of "/newapp".  Problem is 
there seems to be a bug within the sample application or within 
Turbine.  I reported it on this list on 18 May but got no response.  I 
will include the contents of my post below for informational purposes.

- Dan

> I changed by web.xml file in newapp to map the Turbine servlet to be 
> the default servlet by adding the following statement after the 
> servlet element.
> 
>   <servlet-mapping>
>     <servlet-name>newapp</servlet-name>
>     <url-pattern>/</url-pattern>
>   </servlet-mapping>
> 
> Doing this allows me to hit the newapp site using the URL 
> "http://localhost:8080/newapp"; <http://localhost:8080/newapp> versus 
> the URL "http://localhost:8080/newapp/servlet/newapp"; 
> <http://localhost:8080/newapp/servlet/newapp>.  The html login pages 
> form element appears correctly as so...
> 
> <form method="post" 
> action="http://localhost:8080/newapp/action/LoginUser"; 
> <http://localhost:8080/newapp/action/LoginUser>>
> 
> But, when I attempt to Login, I am put back to the login page even 
> with a successful login with the form line changed to this..
> 
> <form method="post" 
> action="http://localhost:8080/newapp/action/LoginUser/action/LoginUser"; 
> <http://localhost:8080/newapp/action/LoginUser/action/LoginUser>>
> 
> Notice is just appended an action/LoginUser to the action.  The screen 
> located at templates/app/screens/Login.vm sets the action with the 
> following Velocity call as follows indicating that the setAction() 
> method does not work correctly in this case.
> 
> <form method="post" action="$link.setAction("LoginUser")">
> 
> In addition, If I hit the newapp site using the new url with a ending 
> slash "http://localhost:8080/newapp/"; <http://localhost:8080/newapp/> 
> the resulting form action appears as follows.
> 
> <form method="post" 
> action="http://172.16.7.15:8080/newapp//action/LoginUser"; 
> <http://172.16.7.15:8080/newapp//action/LoginUser>>
> 
> Adding an addition slash between newapp and action.  This should be 
> fixed as well.  Can someone fix this.
> 
> Thanks,
> 
> - Dan 


Daniel Rall wrote:

> Gary Lawrence Murphy <[EMAIL PROTECTED]> writes:
> 
>> This may fall into the catagory of questions so dumb I can't see the
>> nose on my face, but I can't find the magic to do it; I now it is there
>> someplace.
>> 
>> is it possible to shorten the path of a Velocity page?
>> 
>> My app URL now looks like http://host/app/servlet/app but to be
>> backwards compatible, I must handle GET requests to http://host/app
>> 
>> maybe I just need sleep, but where do I tweak what to make this happen
>> (don't bother telling me to get some sleep, because the Mrs has
>> already tried that ;)
> 
> 
> This is a FAQ (and would be in ours if we had a comprehensive one ;).
> 
> Use mod_rewrite with Apache httpd.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

Reply via email to