第二节:springmvc传值方式
2015-08-23 08:45
537 查看
示例代码:
student.jsp <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>User Information</h2> <form method="POST" action="/HelloWeb/addStudent"> name:<input type="text" name="name"/> <input type="submit" value="click"/> </form> </body> </html> result.jsp <html> <head> <title>Spring MVC Form Handling</title> </head> <body> <h2>Submitted User Information</h2> <table> <tr> <td>Name</td> <td>${name}</td> </tr> </table> </body> </html>
User.java public class User { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } } @Controller public class UserController { <span style="white-space:pre"> </span>@RequestMapping(value = "/user", method = RequestMethod.GET) <span style="white-space:pre"> </span>public String toUser() { <span style="white-space:pre"> </span> return "user"; <span style="white-space:pre"> </span>} @RequestMapping(value = "/add1", method = RequestMethod.POST) public String addStudent(User user, ModelMap model) { model.addAttribute("name", user.getName()); return "result"; } @RequestMapping(value = "/add2", method = RequestMethod.POST) public String addStudent(@RequestParam(value="name")String username,ModelMap model){ <span style="white-space:pre"> </span> model.addAttribute("name", username); <span style="white-space:pre"> </span> return "result"; } @RequestMapping(value = "/add3", method = RequestMethod.POST) public ModelAndView addStudent(String name){ <span style="white-space:pre"> </span> ModelAndView model=new ModelAndView("result"); <span style="white-space:pre"> </span> model.addObject("name", name); <span style="white-space:pre"> </span> return model; } }
相关文章推荐
- 【java】itoo项目实战之EJB中的RMI框架如何设计
- Java中的异常处理
- JAVA自定义异常
- struts2 中文乱码解决办法
- Spring Auto proxy creator example
- Spring AOP Interceptor transaction is not working
- Spring AOP Example – Pointcut , Advisor
- JDBC的使用
- struts2 遍历标签iterator 用法小结
- Spring4.0学习(二)采用@Autowired方式自动获取
- eclipse debug source not fount
- SpringMVC原理流程图
- struts 2 用s 标签 输出 list 里的 map
- springboot 开发入门,及问题汇总
- ubuntu14.04lts如何使用PPA安装JDK8
- springboot 开发入门,及问题汇总
- springboot 开发入门,及问题汇总
- springboot 开发入门,及问题汇总
- 每天五个java相关面试题(8)--spring篇
- Java -- XML解析工具dom4j