Struts: action path (two slashes) in generated HTML form


Web tier: servlets, JSP, Web frameworks: Struts: action path (two slashes) in generated HTML form

  1. Hi,

    I am just starting with struts and I experienced problems already. What I am doing is, forwarding (in the index.jsp) to a Startup action, which decides whether to forward to a login page or to a normal "insider" page.

    If it forwards to the login page, in the form (created with <html:form> the Action request starts with two slashes, not with one. This leads to problems with the browser because the complete URL then only consists of something like;jsessionid=xyz...

    I created a <html:link> element with the same target as the form action, and there it works fine (only one slash).
    Working fine also means that there seems to be some validation where the errors are printed in the page which I interpret as "the action was invoked".

    I use Tomcat 5.0.28 and struts 1.2.4. Tomcat is configured to have multiple hosts, where each host has it's own single web application in the root ("/") context.

    Has anyone any idea?

    Thanks, Jan

    This is my struts-config

    This is the initial forward, used in the index.jsp
       <forward name="welcome" path="/"/>

    Here the actions are defined.

      <action path="/Startup" type="org.biotrull.moviedatabase.Startup" scope="request">
        <forward name="login" path="/pages/Welcome.jsp"/>
        <forward name="movies" path="/pages/movies.jsp"/>
      <action path="/Login" type="org.biotrull.moviedatabase.Login"
        name="LoginForm" scope="request" validate="true"
      <forward name="success" path="/pages/movies.jsp"/>

    And the form bean for the login form.
       <form-bean name="LoginForm" type="org.biotrull.moviedatabase.LoginForm"/>

    Here is the code from the login page where I create the form and the link:

    Here the action expands from "" to "//" in the generated HTML source (I already tried it without the .do)

    <html:form action="/" method="post">
      <td><html:text property="login" size="30" maxlength="255"/></td>
      <td><html:password property="password" size="10" maxlength="10"/></td>
    <!-- this one works fine -->
    <html:link page="">test</html:link>

    Threaded Messages (5)

  2. It should just be:
    <html:form action="" method="post"> (no slash at all)
  3. Thanks for your commend. I tried it without a slash in the form tag, but it leads to the same result.

    I did some research in the struts sources and it looks like the FormTag adds the first slash from the context (which is the root context in my webapp) and the second slash by default.

    The LinkTag uses another method to create the href value, which seems to be able to handle the case of a root-context webapp.

    If I am right there is no workaround but to 'hack' the struts sources, which I would hate.

    So if there is any suggestion helping me to avoid my private 'hack' I would be extremely happy ;-)

  4. Why?[ Go to top ]

    Any particular reason for wanting to put the application in the root context - is it really worth having to create a custom version of Struts for?
  5. Why?[ Go to top ]

    Yes, it is. I want to use Tomcat as Webserver directly and use its virtual host functionality to separate web applications on a single server, and avoid to use different paths in order to do so.

    Besides that - I posted the bug to the struts bugzilla and it is accepted and meanwhile resolved.
    This means, I do not have to maintain my private version of struts in the future an can stay with my root contexts.

    Thanks for any suggestion. Regards! Jan
  6. what is the path of your root context?[ Go to top ]

    hi there,

    when I encountered the same problem I changed the path of the context, as a workaround . First it was path="/", now path="".

    my config:
    Tomcat 5.0.24 with Struts 1.1