Struts中如何找到文件的位置?
我想知道如何在Struts 中找到文件的位置。 文件所在的位置 这是程序的一部分:
<filter-mapping>
<filter-name>LoginFilter</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>
我知道 .do
将是项目中任何文件的扩展名,但我没有获取它的位置。我对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>LoginFilter</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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
.do
是您的 URL 模式(提到@Jigar Joshi),要查看它的映射位置,您必须在浏览器上查看您的 URL:假设您有
http://localhost: 8080/myapp/login.do
,然后.do
被您的 Web 容器看到,并调用您的 Struts Servletorg.apache.struts.action.ActionServlet
>。然后,Struts
ActionServlet
将查看您的相对路径/login
(看看我是如何忽略.do
)并查看它是否映射到您的config
文件(在您的情况下是/WEB-INF/struts-config.xml
)。从那里,Struts
ActionServlet
检查是否存在与您的相对路径匹配的操作路径,如下所示:如果找到
,Struts 将调用com.myapp.action.LoginAction
类并调用execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
方法(如果该类只是一个简单的Action
类)。我希望这有帮助。
在您的
元素中,您可能会发现另一个名为
的元素,例如:forward
name
属性基本上就是您的 Struts 的属性Action 在返回ActionForward
时调用,代码如下:请记住,struts- 中
action
元素内的forward
config.xml 被称为本地 向前。 Global Forward 位于action
元素之外。forward
元素的path
是 Struts 必须调用(以及 web/servlet 容器)呈现的 jsp 页面的相对路径。希望这能为您解决问题。
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 Servletorg.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 yourconfig
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:If that
<action>
is found, Struts will callcom.myapp.action.LoginAction
class and call theexecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
method (if the class is just a simpleAction
class).I hope this helps.
Inside your
<action>
element you might find another element called<forward>
, example:The forward
name
attribute is basically what your Struts Action calls when it returns anActionForward
, a code like this:Bear in mind that a
forward
inside anaction
element instruts-config.xml
is called a local forward. A Global Forward sits outside theaction
element.The
path
of theforward
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.
No ,
.do
将是 URL 模式。每当您点击
/yourapp/login.do
时,特定操作都应该在 struts 中执行,并映射到struts-config.xml
中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 instruts-config.xml