JSP:转发问题
我刚刚开始网络应用程序开发。我有一个只有一行的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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将客户端请求转发到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 调用来执行操作的操作类的类名。类名是完全限定名称。Action
、DispatchAction
、LookupDispatchAction
),您必须找到它的映射并查看 Struts 调用什么方法。landing.do
类型为Action
。因此,请阅读execute()
方法的作用。实际上,所有操作都是 Struts 的execute()
。其他操作只是模板方法模式,它知道通过某种映射调用什么方法。The
<jsp:forward>
forwards a client request to the url declared on thepage
attribute.I also need to mention that in your example, you should have a
/
as first character inside yourpage
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 appendapplication/x-www-form-urlencoded
parameters into your declaration.More info here.
To know what
landing.do
does, do the following:struts-config.xml
(found inWEB-INF
folder in your project) file and find any action (<action>
) that apath="/landing"
) attribute.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.Action
,DispatchAction
,LookupDispatchAction
), you will have to find its mappings and see what method Struts invokes.landing.do
is of typeAction
. Therefore, read what theexecute()
method does. All actions actually, isexecute()
by Struts. The other actions are justTemplate Method
patterns that knows what method to call by some mapping.*.do
的 servlet,?
在这里没有任何意义 - 通常它标记获取参数的开始(如? param=value
)forward
使用指定的内容更改当前页面,而客户端不知道发生了更改。*.do
in your web.xml?
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.此行会将用户转发到网站的另一个页面,特别是 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.