zoukankan      html  css  js  c++  java
  • ssm框架中从controller传值给jsp的方式

    第一种方式是 通过session

    第二种如下:

    如何将controller层值传递到JSP页面

    @RequestMapping(value="/result",method=RequestMethod.GET)
    public String test2(HttpServletRequest request,User user){
    //在此请求中存储属性
    //属性名称/属性值
    request.setAttribute("name1", user.getUsername());
    request.setAttribute("pass1", user.getPassword());

    System.out.println(user.getUsername());
    System.out.println(user.getPassword());

    return "result";
    }

    result.jsp中

    <body>

    <h2>登陆</h2> username:${name1 } <p> password:${pass1 }</p>

    </body>

    第三种:

    使用ModelAndView

    @RequestMapping(value="/result",method=RequestMethod.GET)
    public ModelAndView test2(@RequestParam("username")String user,@RequestParam("password") String pass){
      ModelAndView mav = new ModelAndView();
      mav.setViewName("result");
      mav.addObject("name1", user);
      mav.addObject("pass1",pass);

      System.out.println(user );
      System.out.println(pass);
      return mav;
    }


    result.jsp中

    <body>

    <h2>登陆</h2> username:${name1 } <p> password:${pass1 }</p>

    </body>

  • 相关阅读:
    git分支
    git使用
    多人协作
    python初心记录二
    python初心记录一
    Javascript 概念类知识
    想成为前端工程师?希望读完这篇文章能对你有所帮助。
    Egret note
    cocos2d-js 连连看
    PS置入图片之后保留选区方便C图
  • 原文地址:https://www.cnblogs.com/Samuel-Leung/p/10691158.html
Copyright © 2011-2022 走看看