0

プロジェクトにStruts2を使用しています。簡単な登録プロジェクトに取り組んでいます。ユーザーがログインすると、自分のプロファイルに移動しますが、ブラウザの戻るボタンを押すと、ログイン ページが再び表示されます。XML:

<action name="home" class="bharat.Home">
            <result name="success">/jsp/home.jsp</result>
             <result name="student">/jsp/Welcome.jsp</result>
</action>
<action name="Login" class="bharat.LoginAction">
            <result name="input">/index.jsp</result>
            <result name="success">/jsp/Welcome.jsp</result>
</action>

ホーム.java:

public String execute() {
           if((String)ActionContext.getContext().getSession().get("studentName")!=null)
        {
            return "student";
        }
        if((String) ActionContext.getContext().getSession().get("instructorName")!=null)
        {
            return "instructor";
        }
        session = ActionContext.getContext().getSession();
        session.put("roleName","notAdmin");
        return SUCCESS;
    }

ホーム.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="cache-control" content="no-cache" />
<meta name="expires" content="0" />
<meta name="pragma" content="no-cache" />
    <sx:head/>

ログイン後にユーザーが戻るボタンを押すと、同じページにリダイレクトされる必要があります。誰でも私を助けてくれませんか..

4

3 に答える 3

2

現在の流れは次のようになっていると理解しています。

ユーザーが URL に接続 -> ログイン ページでログインを提供 -> 最初のページをロード

フローを次のように変更することを検討しますか。

ユーザーが URL に接続 -> ログイン ページでログインを提供 -> 最初のページへの自動リダイレクトでページに移動 -> 最初のページを読み込みます。

このようにして、ユーザーが「最初のページ」から戻るボタンを押すと、リダイレクト ページが取得され、自動的に「最初のページ」に戻ります。

于 2012-07-26T13:28:15.977 に答える
0

You can use post and redirect method where all you need to when user login he/she should be redirected to welcome page. If you see banking sites or any other secure site they have deployed the same mechanism and it work perfectly fine.

Secondly i suggest not to play with ActionContext as Struts2 has given you a more clean and flexible way to implement SessionAware interface, by implementing this your Action is free from underlying framework dependencies and easy to test

于 2012-07-26T13:33:58.270 に答える
-1
<script type="text/javascript">
    function fn()
        {   
                 window.open("WelcomeDirect.action","_self");               
        }
</script>
</head>
<body onLoad="fn()">
Reloading.....
</body>

ページのリダイレクト

于 2012-07-27T01:46:55.247 に答える