使用Struts 2在调试器中的动作名称/ url名称 [英] Action name/url name in debuggers using Struts 2

查看:169
本文介绍了使用Struts 2在调试器中的动作名称/ url名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经困扰我,因为我开始使用这个webapp去年(我没有web开发经验)我不知道这个应用程序是否结构不正确,或者这只是它的方式

This has been bothering me since I started working with this webapp last year (I had no experience with web development) I don't know if this app is structured incorrectly or if this is just the way it is.

我的欢迎页面确实是一个登录页面,用户登录后我的应用程序到主页,其中他们具有去到各种其他功能的菜单。

My welcome page is really a login page, and after the user logs in my app goes to a main page, where they have a menu to go to various other functions.

这是 struts.xml

This is struts.xml:

<action name="Welcome">
    <interceptor-ref name="newStack" />
    <result name="success">Login.jsp</result>
</action>

<action name="actLogin" class="actionLogin">
    <interceptor-ref name="newStack" />
    <result name="success">HomePage.jsp</result>
    <result name="error">Login.jsp</result>
</action>

<action name="actHomePage" class="actionHomePage">
    <interceptor-ref name="newStack" />
    <result name="viewUsers">  ViewUsers.jsp</result>
    <result name="addUser">    AddUser.jsp</result>
    <result name="viewWidgets">ViewWidgets.jsp</result>
    <result name="addWidget">  AddWidget.jsp</result>
</action>

JSP文件如下所示: Login.jsp

<s:form action="actLogin" name="formLogin" method="post">
    <s:textfield name="userId" id="txtUserId"/>
    <s:password name="password" id="txtPassword"/>
    .. login submit button ...
</s:form>

HomePage.jsp:

<s:form action="actHomePage" name="formHomePage" method="post">
. . . menu items that set values for action to pick up to route to the correct page
</s:form>

ViewUsers.jsp

<s:form action="actViewUsers" name="formViewUsers" method="post">
    <h2>User List</h2>
    . . .
</s:form>

这样的问题是用户看到的URL和在调试器中列出源文件的URL Chrome,IE或Firefox)总是错误。用户和调试器看到的URL是欢迎在登录页面(这是确定),但他们登录后,他们看到 actLogin.html HomePage 页面上,他们在上看到 HomePage.html > ViewUsers 页面。该网址始终位于您实际使用的网页的后面,因为它使用操作名称。

The problem with this is the URL the user sees and the URLs listing the source files in a debugger (Chrome, IE or Firefox) is always wrong. The URL that the user and debugger sees is Welcome on the login page (which is OK), but after they log in they see actLogin.html on the HomePage page, and they see HomePage.html on the ViewUsers page. The URL is always one behind the page you are actually on because it uses the action name.

如果我的登录JSP 不是具有其表单操作,则将其命名为LOGIN,因为这是正在执行的操作, HomePage

Should my login JSP not have its form action be named LOGIN because while that is the action being performed, the result of that action goes to HomePage?

这个应用程式是否结构非常奇怪,有更好的方法?

Is this app structured weird and there's a better way to do this?

推荐答案

这是由于工作流程设计不良而导致的。要更正它,您应该阅读 PRG模式。您可以更改

This happens as a result of the bad workflow design. To correct it you should read about PRG pattern. You can change

<action name="actLogin" class="actionLogin">
    <interceptor-ref name="newStack" />
    <result name="success" type="redirectAction">actHomePage</result>
    <result name="error">Login.jsp</result>
</action>

<action name="actHomePage" class="actionHomePage">
    <interceptor-ref name="newStack" />
    <result name="success">HomePage.jsp</result>
</action>

不需要其他结果,但如果您需要转到其他页面,在URL中的相同操作。

other results are not needed, but you can remain them if you need to forward to a different page with the same action in the URL.

这篇关于使用Struts 2在调试器中的动作名称/ url名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆