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
Below code can be used in struts.xml to load welcome page.
Execute some Action before loading a welcome page.
<!-- welcome page configuration -begin -->
<action name="" class="com.LoginAction">
<result name="success">login.jsp</result>
</action>
<!-- welcome page configuration -end -->
Return directly some JSP without execution of an Action.
<!-- welcome page configuration -begin -->
<action name="">
<result name="success">login.jsp</result>
</action>
<!-- welcome page configuration -end -->
No <welcome-file-list>
is not needed in web.xml
This worked fine for me, too:
<welcome-file-list>
<welcome-file>MyAction.action</welcome-file>
</welcome-file-list>
I was not able to get the default action to execute when the user enters the webapp using the root of the web app (mywebapp/). There is a bug in struts 2.3.12 that won't go to the default action or use the welcome page when you use the root url. This will be a common occurrence. Once I changed back to struts 2.1.8 it worked fine.
I am almost sure that the OP is the best solution(not sure about best practice, but it works perfectly, and actually is the solution my project leader and I prefer.)
Additionally, I find it can be combined with Spring security like this:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<sec:authorize access="isAnonymous()">
<% response.sendRedirect("/myApp/login/login.action?error=false"); %>
</sec:authorize>
<sec:authorize access="isAuthenticated() and (hasRole('ADMIN') or hasRole('USER'))">
<% response.sendRedirect("/myApp/principal/principal.action"); %>
</sec:authorize>
<sec:authorize access="isAuthenticated() and hasRole('USER')">
<% response.sendRedirect("/myApp/user/userDetails.action"); %>
</sec:authorize>
By this, not only we have control over the first page to be the login form, but we control the flow AFTER user is login in, depending on his role. Works like a charm.