struts2.1.6 + Spring 2.5를 사용하고 있습니다. 응용 프로그램에 4 개의 모듈이 있습니다.struts2에서 URL 인증을 수행하는 방법
- 등록 모듈
- 관리 모듈
- 견적 모듈
- 위치 모듈.
등록 모듈에서 고객은 자신을 등록 할 수 있으며 등록 후에 만 나머지 3 개의 모듈에 액세스 할 수 있습니다.
호출중인 작업이 정상적으로 작동하는 등록 모듈에 속해 있지만 호출중인 작업이 나머지 세 모듈에 속한 경우 먼저 사용자가 로그인했는지 확인해야하는 것처럼 구현하고 싶습니다. 세션이 시간 초과되지 않았습니다. 예이면 정상적으로 진행되어야하며 그렇지 않으면 로그인 페이지로 리디렉션되어야합니다.
연구를 통해 나는이 목적을 위해 인터셉터를 사용할 수 있지만 진행하기 전에 전문가로부터 그것에 대한 피드백을 얻는 것이 더 좋다고 생각했습니다.
어떻게해야하는지 제안하고 가능하면 코드 제안을하십시오.
<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>
여기
내
struts.xml 파일입니다합니다 (struts.xml는 각 모듈에 속하는 네 가지 구성 파일이 포함되어 있습니다)
샘플 admin_config.xml 파일의 이름은
입니다.나머지 두 개의 struts2 xml 구성 파일에는 동일한 코드가 있습니다. 다른 패키지 이름을 가진 네 개의 설정 파일 모두에서 동일한 네임 스페이스를 사용했습니다 (보시다시피)
, 나는 사용자 정의 인터셉터를 작성해야한다는 것을 의미 LoginInterceptor을 말할 수 인터셉터 스택 이름에 "login-required"라는 인터셉터를 추가해야합니다. 내가 맞습니까? –
맞습니다. 웹에서 몇 가지 자습서를 찾을 수 있다고 생각합니다. http://www.vitarara.org/cms/struts_2_cookbook/creating_a_login_interceptor –