Struts中如何找到文件的位置?

发布于 2024-11-01 17:23:07 字数 688 浏览 6 评论 0原文

我想知道如何在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一人独醉 2024-11-08 17:23:07

您的 .do 是您的 URL 模式(提到@Jigar Joshi),要查看它的映射位置,您必须在浏览器上查看您的 URL:

假设您有 http://localhost: 8080/myapp/login.do,然后 .do 被您的 Web 容器看到,并调用您的 Struts Servlet org.apache.struts.action.ActionServlet >。

然后,Struts ActionServlet 将查看您的相对路径 /login(看看我是如何忽略 .do)并查看它是否映射到您的config 文件(在您的情况下是/WEB-INF/struts-config.xml)。

从那里,Struts ActionServlet 检查是否存在与您的相对路径匹配的操作路径,如下所示:

<action path="/login" type="com.myapp.action.LoginAction" name="LoginForm" scope="request">

</action>

如果找到 ,Struts 将调用 com.myapp.action.LoginAction 类并调用 execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception 方法(如果该类只是一个简单的 Action 类)。

我希望这有帮助。


在您的 元素中,您可能会发现另一个名为 的元素,例如:

<forward name="FHome" path="/content/jsp/home.jsp" />

forward name 属性基本上就是您的 Struts 的属性Action 在返回 ActionForward 时调用,代码如下:

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
     return mapping.findForward("FHome");
}

请记住,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 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.

彻夜缠绵 2024-11-08 17:23:07

我知道 .do 将是项目中任何文件的扩展名

No.do 将是 URL 模式。

每当您点击 /yourapp/login.do 时,特定操作都应该在 struts 中执行,并映射到 struts-config.xml

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文