Redirect by value

Login page 
* redirected to the page when the carry data requirements are as follows
1. RedirectAttributes types of parameters in the target controller method
2. The request can not be redirected to the page directly, must springmvc mapping

such as transmission error information
to configure the configuration file in springmvc a parser
<! - To controller can carry data, after mapping springmvc redirected to the page ->
    <mvc:view-controller path="/login" view-name="login"></mvc:view-controller>

For example a sub-layer controller landing page

Application of the parameter values ​​passed parameters RedirectAttributes

// this code source which also exist in a session scope, and a verification code to the user input do comparison, determines whether or not correct. Receiving a pass from a page over the value and the user name, password
     // the key is stored inside the key tools in the domain, based on the verification that the key code value domain session takes 
    @RequestMapping (value = "/ login" , method = RequestMethod.POST)
 public   String Login (the Employee Employee, String code, the HttpSession the session, RedirectAttributes Attributes) {
        String validateCode = (String)session.getAttribute("validateCode");
        session.removeAttribute("validateCode");
        if(!validateCode.equalsIgnoreCase(code)){
            attributes.addFlashAttribute ( "errorMsg", "Error codes" );
             return "the redirect: / Login" ;
        }
        // If the code is correct, the user name and password to verify 
        the Employee EMP = employeeService.login (Employee);
         IF (! EMP = null ) {
            session.setAttribute("loginUser",emp);
            return "redirect:/index.jsp";
        }else{
            attributes.addFlashAttribute ( "error", "user name or password error" );
             return "redirect: / the Login" ;
        }
    }

Then the login page

<TABLE id=table2 cellSpacing=1 cellPadding=0 width="100%"
                                       border=0>
                                    <TBODY>
                                    <TR>
                                        <span style="color:red">${error}</span>
                                        <TD align=middle width=81><FONT color=#ffffff>用户名:</FONT></TD>
                                        <TD><INPUT class=regtxt title=请填写用户名 maxLength=16
                                                   size=16 value=username name=username></TD>
                                    </TR>
                                    <TR>
                                        <TD align=middle width=81><FONT color=#ffffff>密&nbsp;
                                            码:</FONT></TD>
                                        <TD> <the INPUT class = regtxt title = = Please fill in the password of the type password
                                                   maxLength=16 size=16 name=password id=pass></TD>
                                    </TR>
                                    <TR>
                                        <TD align=middle width=81><FONT color=#ffffff >验证码:</FONT></TD>
                                        <TD> <INPUT title = please check and maxLength = 50 size = 12 name = code value = "$ {errorMsg}">
                                            <span><img id="validateCode" src="${pageContext.request.contextPath}/code/getCode?time="+(new Date().getTime()) ></span></TD>
                                    </TR>
                                    </TBODY>
                                </TABLE>

 



Guess you like

Origin www.cnblogs.com/ych961107/p/11978785.html