I wrote a login page today. I believe this is not difficult for everyone, but I am a zombie and I am guilty once!
Submit the form on the login page. In the action, I add a namespace. The details are as follows:
<Form ID = "loginform" Action = "actionpackage/login. Action" method = "Post">... This is omitted... </form>
Login is okay, but the problem is that when my User Name or password is incorrect, I should return to the login page again, and then return again, although through the following method, can be returned 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>
In this case, login.html introduces an external JS file as follows:
<script language="javascript" type="text/javascript" src="jquery-1.8.0.min.js" />
The question is, review the login.html file. When the browser gets the JS file by get, the address obtained by the JS file is relative to the URL. At this time, the problem really arises!
During callback, the URL naturally has more actionpage, resulting in the clear space of actionpage in the get external JS file. Of course, this JS external file cannot be obtained!
The logon URL is http: // localhost: 8080/lfdcwtjxt/actionpage/login. Action.
Return the login page again, JS get 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
Solution:
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 to be searched is no longer in the current namespace. I jumped to another namespace. The default one!
Redirection Configuration:
<package name="default" namespace="/" extends="struts-default"> <action name="login1"><result>/login.html</result></action></package>
Okay. In this way, no namespace is available for the JS get path!
I don't know if there is any other way. Welcome to kick the floor!
The action with namespace is returned to the original page again.