码迷,mamicode.com
首页 > 编程语言 > 详细

Maven和Spring mvc下的页面的跳转与取值

时间:2017-10-09 19:44:06      阅读:874      评论:0      收藏:0      [点我收藏+]

标签:orm   文件   ota   string   html   bsp   div   ann   取值   

(此处tomcat的端口设置为80)

例如:在testForm.jsp里提交表单,在ok.jsp里取值

testForm.jsp页面代码如下:

<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>页面的跳转与取值</title>
</head>
<body>
    <form action="../../api/ceshilei/ceshifangfa" method="post">
        门店编码<input name="num" />
        门店名称<input name="name"/>
        <input id="btnSubmit" type="submit" value="提交"/>
    </form>
    
</body>
</html>

处理器类TestFormSubmit.java进行接收处理,代码如下:

 1 package com.thinkgem.jeesite.modules.store.dao.ceshi1;
 2 
 3 import javax.servlet.http.HttpServletRequest;
 4 import javax.servlet.http.HttpServletResponse;
 5 
 6 import org.springframework.stereotype.Controller;
 7 import org.springframework.ui.Model;
 8 import org.springframework.web.bind.annotation.RequestMapping;
 9 
10 import com.thinkgem.jeesite.common.config.Global;
11 import com.thinkgem.jeesite.modules.store.entity.ceshi1.TestEntity;
12 import com.thinkgem.jeesite.modules.store.entity.daily.TStoresDaily;
13 
14 @Controller   //用于标识是处理器类
15 @RequestMapping(value="api/ceshilei")     //请求到处理器类的绑定
16 public class TestFormSubmit {
17     
18     @RequestMapping(value="ceshifangfa")
19     public String ceshi(TestEntity te, HttpServletRequest request, HttpServletResponse response, Model model){
20         System.out.println("test ing ");
21         model.addAttribute("testentity",te);
22         return "modules/store/ceshi1/ok";
23     }
24     
25 //    @RequestMapping(value="ceshifangfa")          //请求到处理器功能方法的绑定
26 //    public String ceshi(String num, String name, HttpServletRequest request, HttpServletResponse response, Model model){
27 //        System.out.println("test ing ");
28 ////        model.addAttribute("testentity",te);
29 //        model.addAttribute("num",num);
30 //        model.addAttribute("name",name);
31 //        System.out.println("num=="+num);
32 //        System.out.println("name=="+name);
33 ////        return "modules/store/ceshi1/ok";
34 //        return "redirect:ok";    //重定向,值在地址栏有显示,但是页面没有
35 //    }
36     
37     @RequestMapping("toForm")
38     public String toForm() {
39         return "modules/store/ceshi1/testForm";
40     }
41     
42     @RequestMapping("ok")
43     public String ok() {
44         return "modules/store/ceshi1/ok";
45     }
46     
47 }

最终接收值的页面ok.jsp,代码如下:

<%@ page contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>页面的取值</title>
</head>
<body>

    提交的门店编码是${testentity.num }<br>
    提交的门店名称是${testentity.name }<br>
        
</body>
</html>

 

在地址栏输入http://localhost/api/ceshilei/toForm,请求到处理器类value为api/ceshilei的类,并调用请求方法value值为toForm的方法。该toForm方法返回一个要访问的目标文件路径(去掉前缀和后缀的路径,前缀和后缀在spring-mvc.xml中有说明),此处就是testForm.jsp。

在testForm.jsp页面填写表单并提交,action为"../../api/ceshilei/ceshifangfa"。即调用处理器类value为api/ceshilei的类,并调用请求方法value值为ceshifangfa的方法(此处为ceshi)。该方法接收提交的表单传来的值并把值addAttribute给model,并返回一个要访问的目标文件路径。页面跳转到ok.jsp。

ok.jsp用el表达式取值。

Maven和Spring mvc下的页面的跳转与取值

标签:orm   文件   ota   string   html   bsp   div   ann   取值   

原文地址:http://www.cnblogs.com/xsl1995/p/7642384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!