JSP:转发问题

发布于 2024-09-27 22:53:33 字数 712 浏览 0 评论 0原文

我刚刚开始网络应用程序开发。我有一个只有一行的index.jsp。

< jsp:forward page="landing.do?"/>

什么是

  • 上面这行做什么?

  • page="landing.do?"实际指的是?

  • “landing.do?”旁边的问号“?”表示什么?

正如 Bozho 正确指出的那样,一个名为 "action" 的 servlet 被映射到我的 web.xml 中的句柄 "*.do"(如下所示)。



     操作

    *.do;


现在

如何找出与“landing.do”相对应的servlet“action”实际执行的操作?

谢谢。

I am just getting started on web app development. I have an index.jsp that has just ONE line.

< jsp:forward page="landing.do?"/>

What does

  • the above line do?

  • page="landing.do?" actually refer to?

  • what does the question mark "?" next to "landing.do?" signify?

As Bozho rightly pointed out, a servlet called "action" is mapped to handle "*.do" in my web.xml (as shown below).

<servlet-mapping>

    <servlet-name>action</servlet-name>

    <url-pattern>*.do</url-pattern>

</servlet-mapping>

Now

How do I find out what the servlet "action" corresponding to "landing.do" actually does?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

や莫失莫忘 2024-10-04 22:53:33

将客户端请求转发到 page 属性上声明的 url。

我还需要提到的是,在您的示例中,如果您想指定相对 URL,则应该在 page 声明中将 / 作为第一个字符,即:

实际上,这被翻译为重定向到(如果是本地主机)

http://localhost:8080/MyAPP/登陆.do? 会被翻译为 http://localhost:8080/MyAPPLanding.do?)

(您的内容 >? 允许您将 application/x-www-form-urlencoded 参数附加到声明中。

更多信息请参见此处


要了解 landing.do 的作用,请执行以下操作:

  • 转到 struts-config.xml(位于您的 WEB-INF 文件夹中) project) 文件并查找 ) 具有 path="/landing") 属性的任何操作 ()。
  • 找到操作后,就会有一个名为 type 的属性(在该操作内)。该类型是 Struts 调用来执行操作的操作类的类名。类名是完全限定名称。
  • 打开类的 java 文件(如果存在),并根据操作(ActionDispatchActionLookupDispatchAction),您必须找到它的映射并查看 Struts 调用什么方法。
  • 在您的示例中,我的假设将基于您的 landing.do 类型为 Action。因此,请阅读 execute() 方法的作用。实际上,所有操作都是 Struts 的execute()。其他操作只是模板方法模式,它知道通过某种映射调用什么方法。

The <jsp:forward> forwards a client request to the url declared on the page attribute.

I also need to mention that in your example, you should have a / as first character inside your page declaration, if you want to specify a relative URL, i.e.:

This, in effect, is translated as a redirection to (if localhost)

http://localhost:8080/MyAPP/landing.do? (yours would have been translated to http://localhost:8080/MyAPPLanding.do?)

The ? allows you to append application/x-www-form-urlencoded parameters into your declaration.

More info here.


To know what landing.do does, do the following:

  • Go to your struts-config.xml (found in WEB-INF folder in your project) file and find any action (<action>) that a path="/landing") attribute.
  • Once you find your action, there's an attribute called type (inside that action). The type is a the class name of the action class that Struts calls to execute the action. The class name is fully qualified name.
  • Open the java file of the class (if it exists) and depending on the action (Action, DispatchAction, LookupDispatchAction), you will have to find its mappings and see what method Struts invokes.
  • In your example, my assumption will be based that your landing.do is of type Action. Therefore, read what the execute() method does. All actions actually, is execute() by Struts. The other actions are just Template Method patterns that knows what method to call by some mapping.
醉生梦死 2024-10-04 22:53:33
  • 您可能在 web.xml 中有一个映射到处理 *.do 的 servlet,
  • ? 在这里没有任何意义 - 通常它标记获取参数的开始(如 ? param=value)
  • forward 使用指定的内容更改当前页面,而客户端不知道发生了更改。
  • you probably have a servlet mapped to handle *.do in your web.xml
  • the ? means nothing here - generally it marks the start of get parameters (like ?param=value)
  • forward changes the current page with the specified, without the client knowing the change has happened.
没︽人懂的悲伤 2024-10-04 22:53:33

此行会将用户转发到网站的另一个页面,特别是 landing.do

page="landing.do?"实际上指的是landing.do网站的某些页面。我相信这个页面是用Struts框架编写的。 (但也可以是其他)

问号“?”表示什么?在“landing.do?”旁边在这种情况下没有任何意义。一般在“?”之后应该有一个请求参数列表。在这种情况下,将没有参数。

更新:
您应该找到映射到该 servlet 名称的 servlet 类。之后,您将能够尝试了解该 servlet 类的作用。另外,请查看 Struts 教程或规范以了解 Struts 框架工作流程。

This line will forward user to another page of the site, in particular to landing.do

page="landing.do?" actually refer to some page of the site landing.do. I believe this page is written with Struts framework. (But can be other)

what does the question mark "?" next to "landing.do?" mean nothing in this case. Generally after "?" there should be a list of request parameters. In this cases there will just be no parameters.

Update:
You should find servlet class which is mapped to that servlet name. After that you will be able to try to understand what that servlet class does. Also, look at the Struts tutorials or specification to get understanding of Struts framework workflows.

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