java 我可以在点击 html 页面中的 html 链接时调用 Struts2 操作吗
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3774751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I call a Struts2 action on click of a html link in html page
提问by Dhora
I want a Struts2 action to be performed on click of a html link in a html page. My first question is whether is it possible to perform a Struts2 action in a html page(not JSP)? If yes, take a look at my code below:
我希望在单击 html 页面中的 html 链接时执行 Struts2 操作。我的第一个问题是是否可以在 html 页面(不是 JSP)中执行 Struts2 操作?如果是,请看下面我的代码:
home.html
主页.html
href="home.action"
href="home.action"
struts.xml
struts.xml
action name="home" class="com.struts.action.HomeAction"
result name="Success">loginJSP.jsp
动作名称="home" class="com.struts.action.HomeAction"
result name="Success">loginJSP.jsp
*****web.xml***** I did filter mapping such that everything goes to Struts2
*****web.xml***** 我做了过滤器映射,这样一切都去 Struts2
回答by sjt
Have you tried this?
你试过这个吗?
<a href="<s:url action="actionName"/>">click here</a>
Or this?
或这个?
<a href="/abc/actionname.action">Click here</a><br />
Also see: http://struts.apache.org/2.x/docs/url.html
另见:http: //struts.apache.org/2.x/docs/url.html
Just curious to know, why can't you use JSP?
只是想知道,为什么不能使用 JSP?
回答by Accollativo
<s:url action="actionNameInStrutsXML" method="methodNameInYourClass" var="menuAdmin" />
<s:a href="%{menuAdmin}">Menu</s:a>
In this way you can call the method that you prefer.
通过这种方式,您可以调用您喜欢的方法。
Remember to put in your struts config this:
记得在你的 struts 配置中输入:
struts.enable.DynamicMethodInvocation" value="true"
struts.enable.DynamicMethodInvocation" value="true"