struts2.1.6 + Spring 2.5 を使用しています。アプリケーションには 4 つのモジュールがあります。
- 登録モジュール
- 管理モジュール
- 見積もりモジュール
- ロケーションモジュール。
登録モジュールでは、顧客は自分自身を登録することができ、登録後にのみ残りの 3 つのモジュールにアクセスできるようになります。
呼び出されているアクションが登録モジュールに属している場合は通常どおりに機能しますが、呼び出されているアクションが残りの 3 つのモジュールに属している場合は、最初にユーザーがログインしており、セッションがないかどうかを確認する必要があります。タイムアウトしました。はいの場合は、通常どおり続行する必要があります。それ以外の場合は、ログイン ページにリダイレクトする必要があります。
調査を通じて、インターセプターをこの目的に使用できることがわかりましたが、先に進む前に、専門家からフィードバックを得たほうがよいと考えました。
それがどのように行われるべきかを提案し、可能であればコードの提案をいくつか入れてください。
これが私のstruts.xmlファイルです (struts.xml には、各モジュールに属する 4 つの異なる構成ファイルが含まれています)。
<struts>
<include file="struts-default.xml" />
<constant name="struts.i18n.reload" value="false" />
<constant name="struts.objectFactory" value="spring" />
<constant name="struts.devMode" value="false" />
<constant name="struts.serve.static.browserCache" value="false" />
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<constant name="struts.multipart.maxSize" value="10000000" />
<constant name="struts.multipart.saveDir" value="C:/Temporary_image_location" />
<include file="/com/action/mappingFiles/registration_config.xml" />
<include file="/com/action/mappingFiles/admin_config.xml" />
<include file="/com/action/mappingFiles/quote.xml" />
<include file="/com/action/mappingFiles/location_config.xml" />
</struts>
サンプルのregistration_config.xmlファイルは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="registration" extends="struts-default"
namespace="/my_company">
<action name="LoginView" class="registration" method="showLoginView">
<result>....</result>
<result name="input">...</result>
</action>
</package>
</struts>
サンプルのadmin_config.xmlファイルは次のとおりです。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="admin" extends="struts-default"
namespace="/my_company">
<action name="viewAdmin" class="admin" method="showAdminView">
<result>....</result>
<result name="input">...</result>
</action>
</package>
</struts>
残りの 2 つの struts2 xml 構成ファイルにも同じコードがあります。4つの構成ファイルすべてで、パッケージ名が異なる同じ名前空間を使用しました(ご覧のとおり)