Home > Article > Web Front-end > The action with the namespace returns to the original page again, the error caused by the namespace_html/css_WEB-ITnose
Today I wrote a landing page. I believe this is not difficult for everyone, but as a silk girl, I made a mistake once!
The login page form is submitted. In the action, I added the namespace. The details are as follows:
<form id="loginForm" action="actionPackage/login.action" method="post"> ...此处省略...</form>
Login is fine. Problem, but the problem is that when my username or password is wrong, I should return to the login page. When I return, although the following method can be used to return to the specified html document
<package name="actionPackage" namespace="/actionPackage" extends="struts-default" > <action name="login" class="loginAction" method="execute"> <result name="success">/WEB-INF/index.html</result> <result name="error" >/login.html</result> </action> </package>At this time, the problem comes. login.html introduces an external js file. The details are as follows:
<script language="javascript" type="text/javascript" src="jquery-1.8.0.min.js" />The problem lies here. When login.html is returned, the browser gets the js file. file, since the js file acquisition address is relative to the url, at this time, the problem really arises!
When logging in to submit the form, the actionPage namespace will be added to the URL. Then when returning to login.html, the URL will naturally include actionPage, causing the path to be obtained when getting the external js file. There is also an obvious space called actionPage in the file. Of course, this js external file cannot be obtained!
The url when logging in becomes http://localhost:8080/lfdcwtjxt/actionPage/login.action
When you return to the login page, the js acquisition path becomes http:/ /localhost:8080/lfdcwtjxt/actionPage/jquery-1.8.0,js
This is wrong, it should be http://localhost:8080/lfdcwtjxt/jquery-1.8.0,js
The solution is:
Use redirection to solve the problem: the configuration is as follows
<package name="actionPackage" namespace="/actionPackage" extends="struts-default" > <action name="login" class="loginAction" method="execute"> <result name="success">/WEB-INF/index.html</result> <result name="error" type="redirect">/login1</result> </action></package>Note: When redirecting, I used a slash /, that is to say , the action you are looking for is no longer in the current namespace, and jumps to another namespace, the default one!
Redirect configuration:
<package name="default" namespace="/" extends="struts-default"> <action name="login1"> <result>/login.html</result> </action></package>Okay, so the js acquisition path does not have the previous namespace!
I don’t know if there is any other way, welcome to kick the floor!