Can Javascript on client side access Struts form?
In Struts say we define some form with the name TaskForm
in struts-config.xml
.
In one of the javascript function, I can see the sta开发者_如何学Gotement:
document.TaskForm(some form name in struts-config.xml).action = action
My question here is how come we are able to execute document.taskform
at client side?
I mean statements like document.getElementByid("")
are defined in browser side but not sure about document.taskform
?
You can't access Struts ActionForms using JavaScript!
What you are seeing is JavaScript interaction with the HTML client side <form>
tag (something like this tutorial presents)
The HTML <form>
tag happens to have the same attribute name
and action
value as the ones from the <form-bean>
and <action>
tags of struts-config.xml
.
This is no coincidence!
ActionForm
s are the server side object representation of a client side HTML <form>
tag and Struts server tags generate HTML which is then sent to the client.
The HTML <form>
tag usually contains the name of the bean specified in <form-bean>
of struts-config.xml
tag, while the action
attribute of the <form>
is the one specified in the corresponding <action>
of struts-config.xml
.
Some names and values are preserved to maintain clarity of the code. This makes things homogeneous. But we are NOT talking about the same thing!
精彩评论