Spring Web MVC의 ModelAndView를 사용하여 동일한보기 컨트롤러를 반환합니다.

StackOverflow https://stackoverflow.com/questions/1642784

  •  10-07-2019
  •  | 
  •  

문제

응용 프로그램을 개발하기 위해 Spring Web MVC 및 Hibernate를 사용하고 있습니다.

내 login.jsp 페이지에 다음 코드가 있습니다.

<form:form method="post" commandName="User">
   User Name : 
      <form:input path="email"/>
   Password : 
     <form:input path="password"/>

<input type="submit" align="center" value="Execute">

이제 내 servlet.xml 파일은 다음 코드가 있습니다.

 <bean name="/uservalidate.htm" class="com.sufalam.mailserver.presentation.web.UserValidateFormController">
        <property name="sessionForm" value="true"/>
        <property name="commandName" value="User"/>
        <property name="commandClass" value="com.sufalam.mailserver.bean.User"/>
        <property name="formView" value="login"/>
        <property name="successView" value="layout.jsp"/>
        <property name="userSecurityProcessor" ref="IUserSecurityProcessor"/>
    </bean>

내 uservalidateformcontroller는 다음 코드를 가지고 있습니다.

public class UserValidateFormController extends SimpleFormController {

    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
    private IUserSecurityProcessor userSecurityProcessor;

    public ModelAndView onSubmit(Object command)
            throws ServletException, SufalamException {
            ModelAndView mav = new ModelAndView();
            Map model = new HashMap();


        String username = ((User) command).getEmail();
        String password = ((User) command).getPassword();
        List userChecking = new ArrayList();
        userChecking = userSecurityProcessor.findByAll(username, password, 0.0);
        System.out.println("userChecking length = "+userChecking.size());
        if (userChecking.size() == 1) {
            return new ModelAndView("layout");
            //return new ModelAndView(new RedirectView(getSuccessView()));
        }

        return new ModelAndView("login", model);

    }

    protected Object formBackingObject(HttpServletRequest request) throws ServletException {
        User user = new User();
        return user;
    }

  public void setUserSecurityProcessor(IUserSecurityProcessor userSecurityProcessor) {
        this.userSecurityProcessor = userSecurityProcessor;

    }

제출 이벤트를 나눠주는 시점의 uservalidateformcontroller에서 사용자 이름과 비밀번호가 정확한지 확인하고 있습니다.

잘 작동하고 둘 다 일치한다면 Layout.jsp로 리디렉션하면 괜찮습니다.

그러나 사용자 이름이나 암호가 올바르지 않은 경우 동일한 login.jsp 페이지로 리디렉션하고 적절한 오류를 표시하고 싶습니다.

동일한 뷰 컨트롤러로 반대하는 일을 해결하는 솔루션을 제안 해주세요 ..

미리 감사합니다 ..

도움이 되었습니까?

해결책

마지막으로 다음 코드 라인 으로이 문제를 해결하십시오.

return new ModelAndView(new RedirectView(getSuccessView()));

또는

return new ModelAndView(new RedirectView("success.htm");

감사...

다른 팁

당신이있는 경우 InternalResourceViewResolver 구성된 경우 다음과 같이 할 수 있습니다.

return new ModelAndView("redirect:success.htm");

제 생각에는 이것은 더 명확합니다.

나는 당신이해야 할 일은 다시 사용하기 전에 당신의 모델을 채우는 것뿐입니다.

    if (userChecking.size() == 1) {
        return new ModelAndView("layout");
        //return new ModelAndView(new RedirectView(getSuccessView()));
    }
    model.put("User", command);
    return new ModelAndView("login", model);

... 이것이 당신이 찾고있는 것인지 확실하지 않지만 이것이 내가 당신의 문제를 해결하는 방법입니다.

    else { return new ModelAndView( "login", model ); }

... 그렇지 않으면 나는 당신의 질문에서 무언가를 놓쳤습니다. 당신이 이렇게 붙어있는 것은 꽤 멀리있는 것 같습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top