0
@Controller
@RequestMapping("Page/Login.do")
public class HomeController
{
    @RequestMapping(method = RequestMethod.GET)
    protected String showLoginPage(HttpServletRequest req,BindingResult result) throws Exception
    {
        loginuser lu=new loginuser();
        lu.setLoginn("Amit");
        System.out.println(lu.getLoginn());
        return "Login";
    }
}

上面的代码是##HomeController.java##

登录用户.java

package Com.Site.Name.Order;

public class loginuser
{
        private String Loginn;


        public String getLoginn()
                {
            System.out.println("hi i m in login get");
            return Loginn;
        }

        public void setLoginn(String loginn) 
                {
            System.out.println("I m in Loin set");
            Loginn = loginn;
        }   
}

我的 JSP 页面是

登录.jsp

<form:form action="Login.do" method="post" commandName="loginuser">
    <div id="Getin">
        <img alt="" src="Image/loginttt.png">
    </div>
    <div id="login">    
    </div>

    <form:input path="Loginn"/>
    <input type="submit" value="LOGIN"/>
</form:form>
4

1 回答 1

0

您正在尝试使用Model属性 ( commandName),但没有将此类属性添加到模型或请求属性中。您需要添加它。此外,BindingResult您的处理程序中的 没有意义。去掉它。

@RequestMapping(method = RequestMethod.GET)
protected String showLoginPage(HttpServletRequest req, Model model) throws Exception
{
    loginuser lu=new loginuser();
    lu.setLoginn("Amit");
    System.out.println(lu.getLoginn());
    model.addAttribute("loginuser", lu);
    return "Login";
}

这些Model属性被添加到请求属性中,因此在jsp.

于 2013-10-09T16:16:49.853 回答