Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 319
mrowe Avatar asked Sep 02 '08 12:09

mrowe


People also ask

How do you call an action in struts?

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.

What does .do mean in struts?

*. 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.

What is action path in struts-config xml?

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.

Where do the location of struts-config xml is specified?

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>


1 Answers

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.

like image 143
Martin McNulty Avatar answered Sep 17 '22 17:09

Martin McNulty