zoukankan      html  css  js  c++  java
  • [原创]Spring MVC 学习 之

    原文参考地址:

    http://www.cnblogs.com/rhythmK/p/3971191.html

    目的和缘由:

    本人想做一个分享的页面,分析给朋友注册,注册按分享ID进行级联;

    过程:

    很多波折;

    再这记录正确的方法;

    分享,通过URL分享,所以分享的ID一定要放在URL里;

    懂得这个就比较好做了.

    当然要在懂得spring mvc mapping的原理上往下看

    第一步:

    在生成的时候,后面跟上参数. 这步是关键.

    1 <div class="botton-button" style="text-align: center;padding-top: 10px">
    2 <form method="post">
    3 <button type="submit" formaction="share.do?shareid=${shareid}">生成邀请链接</button>
    4 <button type="submit" formaction="fanlilist.do">邀请返利</button>
    5 <button type="submit" formaction="resetpassword2.do">修改密码</button>
    6 </form>
    7 </div>

    其中share.do 是我截取servlet的规则.

    ?shareid=${shareid}

    其中{shareid} 也是从上一级页面的跳转中拿到的.

    如果是直接的话,可以写成

    ?share=A0001

    第二步:

    截取share.do,见代码

     1     @RequestMapping(value="share.do")
     2     public String ShareFriend(Model model, HttpSession session, ServletRequest request){
     3 
     4         String shareID =  request.getParameter("shareid");
     5         System.out.println(shareID);
     6         if (shareID == null || shareID.isEmpty()) {
     7             //return new ModelAndView("404");
     8             return "404";
     9         }
    10         
    11         //return new ModelAndView(new RedirectView("/share.do?shareid=" + shareID,true)).addObject("shareid",shareID);
    12         model.addAttribute("shareid", shareID);
    13         return "Share";
    14     }

    通过

    request.getParameter("shareid");

    来获取URL中的参数.

    再发参数通过值绑定到页面中.

    第三步,

    在分享页面.跳转的地方,加上这个shareid,也是通过URL传递过去.这样就好啦..

    1             <a href="register2.do?shareid=${shareid}" target="_blank"> <img
    2                 src="image/yq.jpg" class="sharePic">点击此图后跳到注册页面
    3             </a>

    是不是很简单呢?

    知道了,知道简单,不知道就难.

    现在面临下一个问题.

    Spring mvc怎么传值到下拉框.......

    有在线的大神吗?

  • 相关阅读:
    openresty开发系列35--openresty执行流程之5内容content阶段
    openresty开发系列34--openresty执行流程之4访问阶段
    openresty开发系列33--openresty执行流程之3重写rewrite和重定向
    [转] Dangers of using dlsym() with RTLD_NEXT
    fork failed because of Out Of Memory
    gdb 拾穗
    原子变量的性能问题
    blktrace + blkparse + btt 分析IO
    [转] 利用BLKTRACE分析IO性能
    使用perf + FlameGraph生成进程火焰图
  • 原文地址:https://www.cnblogs.com/SamRichard/p/5039100.html
Copyright © 2011-2022 走看看