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.
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>
The JSP files look like this: 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>
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.
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…