Struts 2设置默认操作 [英] Struts 2 set default action
问题描述
大家好。
我正在使用struts2框架处理java web应用程序。在这个应用程序中,我有一个登录
操作,我希望这是我的应用程序的默认操作。换句话说,我希望当我运行应用程序时,登录
操作执行,我的网址如下:
http :// localhost:8080 / MyWebApplication / login
所以我需要在我的项目中设置默认操作
。但我不知道... :(
我的 struts.xml
文件的一部分是这样的:
< package name = login namespace = / extends = struts-default >
< action 名称 = 登录 小号pan> class = Action.loginAction >
< result name = 成功 type = redirectAction >
< param name = actionName > search < / param >
< param name = 名称空间 > / < / param >
< / result >
< result name = 错误 > /login.jsp< / res ult >
< 结果 名称 = 输入 > /login.jsp < / result >
< ; / action >
< / package >
i尝试
< default-action -ref 名称 = 登录 / >
在我的登录包中,但没有任何效果。
任何人都可以帮我解决我的问题?
提前感谢。
对于web app web.xml文件是入口点。因此,您必须在Web应用程序中将jsp文件作为欢迎文件提及,然后将请求重定向到jsp页面中的登录操作。您的jsp页面仅包含重定向代码以重定向到struts操作(即登录操作)
Hi everyone.
i am working on java web application with struts2 framework. in this application, i have a login
action that i expect to be the default action of my application. in other words, i expect that when i run application, login
action execute and my url be like this:
http://localhost:8080/MyWebApplication/login
so i need to set default action
in my project. but i don't know... :(
the part of my struts.xml
file is like this:
<package name="login" namespace="/" extends="struts-default">
<action name="login" class="Action.loginAction">
<result name="success" type="redirectAction">
<param name="actionName">search</param>
<param name="namespace">/</param>
</result>
<result name="error">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
i tried
<default-action-ref name="login" />
in my login package, but doesn't any effect.
could anyone help me to solve my problem?
thanks in advance.
for web app web.xml file is the entry point. So you have to mention a jsp file as a welcome file in your web app and then redirect the request to your login action in the jsp page.i.e your jsp page contains only redirection code to redirect to the struts action(i.e. login action)
这篇关于Struts 2设置默认操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!