How can I set the welcome page to a struts action?

后端 未结 15 1967
天涯浪人
天涯浪人 2020-11-29 20:15

I have a struts-based webapp, and I would like the default \"welcome\" page to be an action. The only solutions I have found to this seem to be variations on making the welc

相关标签:
15条回答
  • 2020-11-29 21:00

    I have configured like following. it worked perfect and no URL change also...

    Create a dummy action like following in struts2.xml file. so whenever we access application like http://localhost:8080/myapp, it will forward that to dummy action and then it redirects to index.jsp / index.tiles...

    <action name="">
        <result type="tiles">/index.tiles</result>
    </action>
    

    w/o tiles

    <action name="">
        <result>/index.jsp</result>
    </action>
    

    may be we configure some action index.action in web.xml as <welcome-file>index.action</welcome-file>, and use that action to forward required page...

    0 讨论(0)
  • 2020-11-29 21:02

    I would create a filter and bounce all requests to root back with forward responce. Hacks with creating home.do page looks ugly to me (One more thing to remember for you and investigate for someone who will support your code).

    0 讨论(0)
  • 2020-11-29 21:08

    there are this answer above but it is not clear about web app context so i do this:

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>TilesDispatchServlet</servlet-name>
        <servlet-class>org.apache.tiles.web.util.TilesDispatchServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>TilesDispatchServlet</servlet-name>
        <url-pattern>*.tiles</url-pattern>
    </servlet-mapping>
    

    And in index.jsp i just write:

    <jsp:forward page="index.tiles" />
    

    And i have index definition, named index and it all togather work fine and not depends on webapp context path.

    0 讨论(0)
  • 2020-11-29 21:09

    "Surely there's a better way!"

    There isn't. Servlet specifications (Java Servlet Specification 2.4, "SRV.9.10 Welcome Files" for instance) state:

    The purpose of this mechanism is to allow the deployer to specify an ordered list of partial URIs for the container to use for appending to URIs when there is a request for a URI that corresponds to a directory entry in the WAR not mapped to a Web component.

    You can't map Struts on '/', because Struts kind of require to work with a file extension. So you're left to use an implicitely mapped component, such as a JSP or a static file. All the other solutions are just hacks. So keep your solution, it's perfectly readable and maintainable, don't bother looking further.

    0 讨论(0)
  • 2020-11-29 21:10

    This works as well reducing the need of a new servlet or jsp

    <welcome-file-list>
    <welcome-file>/MyAction.action</welcome-file>
    </welcome-file-list>
    
    0 讨论(0)
  • 2020-11-29 21:12

    It appears that a popular solution will not work in all containers... http://www.theserverside.com/discussions/thread.tss?thread_id=30190

    0 讨论(0)
提交回复
热议问题