The action with namespace is returned to the original page again.

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.