12.07.2015 Views

4.3.1.Action의 역할 - Anyframe

4.3.1.Action의 역할 - Anyframe

4.3.1.Action의 역할 - Anyframe

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ControllerString userId = userForm.getUserId();String password = userForm.getPassword();//사용자 Id, Password 체크if ((userId != null && userId.equals("anyframe"))&& (password != null && password.equals("anyframe"))) {//로그인 성공시 Session에 사용자 정보를 저장한다.Set principals = new HashSet();Set credentials = new HashSet();//사용자의 이름과 권한을 저장한다.principals.add(new TypedPrincipal("<strong>Anyframe</strong>", TypedPrincipal.USER));principals.add(new TypedPrincipal("ADMIN", TypedPrincipal.GROUP));Subject subject = new Subject(false, principals, credentials,credentials);HttpSession session = request.getSession();session.setAttribute("subject", subject);}}} else {throw new FailedLoginException();}return (mapping.findForward("success"));execute()메소드가 호출되면 ActionForm에 저장된 userid 와 password 값을 받아오고 사용자 인증이성공하면(위에서는 비지니스 서비스없이 임시로 anyframe/anyframe 에 대해 ADMIN 사용자로 체크함) Subject객체를 Session에 설정한 후 sucess로 지정된 ActionForward를 리턴한다. 인증에 실패할경우에는 FailedLoginException을 발생시켜 struts-config.xml에 설정된 Exception처리 설정을 따른다.• Action 매핑 예아래는 위의 LoginAction.java의 매핑 정보를 설정한 struts-config-login.xml의 일부이다.• Spring Bean 형태의 비즈니스 서비스 InvokeSpring Framework에서는 Struts와의 통합을 위해 spring-webmvc-struts의 ActionSupport(내부적으로Struts의 Action을 extends하고 있음)를 제공하고 있다. Struts의 Action클래스 대신 ActionSupport 클래스를 extends하면 Spring Framework Bean형태의 비즈니스 서비스에 쉽게 접근이 가능하다. 사용방법은 다음과 같다.public class SampleAction extends ActionSupport {public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)throws Exception {ApplicationContext ctx = getWebApplicationContext();BusinessService businessService =(BusinessService)ctx.getBean("businessService");18

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!