質問

アプリケーションの開発に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で、ユーザー名とパスワードが正しいかどうかを確認しています。

正常に動作しています&amp;両方が一致する場合、layout.jspへのリダイレクトも問題ありません。

ただし、ユーザー名またはパスワードが間違っている場合は、同じlogin.jspページにリダイレクトし、適切なエラーを表示します。

同じView Controllerにリダイレクトする方法を提案してください。

事前に感謝します。

役に立ちましたか?

解決

最後に次のコード行でこの問題を解決します:

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