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 welcome page a JSP that contains a redirect to the action. For example, in web.xml
:
<welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list>
and in index.jsp
:
<% response.sendRedirect("/myproject/MyAction.action"); %>
Surely there's a better way!
Struts 2 “action” tag is used to call action class directly from a JSP page. if the “executeResult” attribute is set to true, the content of the result page will be rendered directly in the current page.
*. do is a directive in the web. xml file that tells the application server to send all form actions to the controller. The controller then takes whatever the first part of the statement (eg. if action.do, then uses action) and compares it against what is in your struts-config.
The action-mappings section of the struts-config. xml file is by far the most important one because it is the one that defines the application's workflow: This determines which request is mapped to which Action subclass and, from there, which possible forwards can be invoked, adding the global-forwards to the list.
xml file of the fault module is represented as fault-struts-config. xml and is present in <Web NMS Home>/webclient/fault/conf directory. The configuration file basically contains three main elements: <form-beans>
Personally, I'd keep the same setup you have now, but change the redirect for a forward. That avoids sending a header back to the client and having them make another request.
So, in particular, I'd replace the
<% response.sendRedirect("/myproject/MyAction.action"); %>
in index.jsp with
<jsp:forward page="/MyAction.action" />
The other effect of this change is that the user won't see the URL in the address bar change from "http://server/myproject" to "http://server/myproject/index.jsp", as the forward happens internally on the server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With