How to find out the location of the file in Struts?
I want to know that how to find out the location of a file in Struts. Where the files would be situated Here is some part of program:
<filter-mapping>
<filter-name>LoginFilte开发者_StackOverflow中文版r</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<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>2</load-on-startup>
</servlet>
I know that .do
would be the extension of any file in the project but I am not getting its location. I don't know anything about struts.
Thanks in advance
Your .do
is your URL pattern as (@Jigar Joshi mentioned) to see where it's mapped you will have to look at your URL on your browser:
Supposed your have http://localhost:8080/myapp/login.do
, then the .do
is seeing by your web container and it calls your Struts Servlet org.apache.struts.action.ActionServlet
.
The Struts ActionServlet
will then see your relative path /login
(see how I've ignored the .do
) and see whether it's mapped on your config
file (in your case /WEB-INF/struts-config.xml
).
From there, Struts ActionServlet
check if there's an action path that matches your relative path, something like this:
<action path="/login" type="com.myapp.action.LoginAction" name="LoginForm" scope="request">
</action>
If that <action>
is found, Struts will call com.myapp.action.LoginAction
class and call the execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
method (if the class is just a simple Action
class).
I hope this helps.
Inside your <action>
element you might find another element called <forward>
, example:
<forward name="FHome" path="/content/jsp/home.jsp" />
The forward name
attribute is basically what your Struts Action calls when it returns an ActionForward
, a code like this:
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
return mapping.findForward("FHome");
}
Bear in mind that a forward
inside an action
element in struts-config.xml
is called a local forward. A Global Forward sits outside the action
element.
The path
of the forward
element is the relative path of the jsp page that Struts has to call (and the web/servlet container) to render.
Hope this clears things out for you.
I know that .do would be the extension of any file in the projec
No , .do
would be the URL pattern.
Whenever you hit /yourapp/login.do
particular action is supposed to be executed in struts and that is mapped in struts-config.xml
精彩评论