Configure a welcome page in Struts
Every website need a welcome or default page as an entry point. Here’s 3 ways to configure a welcome page in Struts.
1. index.jsp
The simplest way is create a “index.jsp” page and put it same level with the WEB-INF folder, project root folder.
Access the project root
http://localhost:8080/StrutsExample/
It will default to index.jsp internally.
http://localhost:8080/StrutsExample/index.jsp
2. web.xml welcome file
Declare a welcome-file in web.xml file.
<welcome-file-list> <welcome-file> /pages/Welcome.jsp </welcome-file> </welcome-file-list>
Access the project root
http://localhost:8080/StrutsExample/
It will redirect to welcome.jsp file internally.
http://localhost:8080/StrutsExample/pages/Welcome.jsp
web.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Maven Struts Examples</display-name> <servlet> <servlet-name>action</servlet-name> <servlet-class> org.apache.struts.action.ActionServlet </servlet-class> <init-param> <param-name>config</param-name> <param-value> /WEB-INF/struts-config.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file> /pages/Welcome.jsp </welcome-file> </welcome-file-list> </web-app>
3. JSP Forward
Create a “index.jsp” file as stated in method 1, and define a JSP forward tag to redirect it to another Struts action.
index.jsp
<jsp:forward page="Welcome.do"/>
Declare a /Welcome web path, with a ForwardAction type to forward it to another JSP file.
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_3.dtd"> <struts-config> <action-mappings> <action path="/Welcome" type="org.apache.struts.actions.ForwardAction" parameter="/pages/Welcome.jsp"/> </action-mappings> </struts-config>







specify the action in the view. as /login for example.
in the struts-config xml, it should be mapped to a form bean and corresponding action class
I got the error below:
Struts Problem Report
Struts has detected an unhandled exception:
Messages:
There is no Action mapped for namespace [/] and action name [] associated with context path [].
How to solve it?
Struts 1.x and 2.x are popular. which one is the trend? which one is most widely used?
for a career, which should be chosen?
Awesome tutorial. Thank you so much. This is so so helpful for beginners like me.
/pages/Welcome.jsp really means a Welcome.jsp inside a pages folder within the WebContent folder.
Hope this helps someone.
if we put a jsp page inside the WEB-INF folder, its more secure. no access from outside.
hi what is
[...] Configure a welcome page in Struts Configure a welcome page in Struts. [...]