Passing values between pages, mvc parameter problem (front and back)

Passing values ​​between pages ===============

Use the built-in object request to a page
<%request.setAttribute("txt", "Life service") %>
The second page
<% String txt = request.getAttribute("txt") %> (attribute)
<th><%=txt %></th>

can also pass the "life service" of a page as a parameter (?txt=life service) to The second page, use <%request.getParameter("txt") %> to get it (parameters)

This is equivalent to the value stack, or you can directly use <input type="hidden" name="roleid" id="roleid" value="${id}">

var roleId=$("#roleid").val();//This implements jsp--js//Hidden domain


======= ============================
In the model add, the parameter passed when jumping is, passed to the page to be jumped later, in The annotations in mvc often indicate the page to be jumped. The method parameters under the label are the parameters of the previous request for this page, and the method body is the parameters returned to the annotation after processing these parameters. The hidden field is used before the jump? Or model.set is passed in, and then the annotation page is obtained with a hidden field, and then js is obtained. Pass the value to the page
to be jumped and
return "
model.addAttribute("szie", szie);, after the index receives the size, modeladd can go to the value stack before jumping, and the index directly uses the jstl expression to use


model.addObject("parentMenus", parentMenus); /// ///////////////////////////////////////////// ////////// A key, corresponding to a value

without calling back the value stack, use model.addAttribute at this time jsp use this
<%-- <c:choose>
                        <c:when test="${ roledetl.status==1}">
                        <input class="width_240" name="status" value="valid" />
                        </c:when>
                         <c:when test="${roledetl.status==0} ">
                        <input class="width_240" name="status" value="Not valid" />
                        < /c:when>
                       </c:choose> --%>
                      <%--  <c:if test="${roledetl.status==1}">
                       <input class="width_240" name="status"   value=" 有效" />
                       </c:if> --%>
                        <select name="status" class="width_240">
                                <option value="1" <c:if test="${roledetl.status==1}">selected="selected"</c:if>>有效</option>
                                <option value="0" <c:if test="${roledetl.status==2}">selected="selected"</c:if>>无效</option>
                         </select>
                         <select name="status" class="width_240">
                                <option value="0" selected="selected">===请先选择===</option>
                                <c:forEach items="${item}" var="item" >
                                <option value="${item.id }" selected="selected">${item.name }</option>
                                </c:forEach>
                         </select>

不用回调用值栈, 用model.addAttribute前台用jstl表达式




==============================================================
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>



<td><select name="org" class="width_240">
                                <option value="0" selected="selected">===请先选择===</option>
                                <c:forEach items="${orgs}" var="item" >
                                <option value="${item.id }" >${item.orgName }</option>
                                </c:forEach>
                         </select>
                         </td>

@RequestMapping(value = "/edit")
    public void edit(Long id,Model model) {

        if (id != null) {
        User roledetl = userService.getUserForEditById(id);
            model.addAttribute("roledetl", roledetl);
           List<Organization> orgs=  organizationService.getOrganization();
            model.addAttribute("orgs", orgs);
//            model.addAttribute("areas", acountService.getDictDataListByTypeCodeAndParentId(StaticUtil.PROVINCE_CITY, organization.getCityId()));
        }
//        model.addAttribute("provinces", acountService.getDictDataListByTypeCode(StaticUtil.PROVINCE_CITY));
//        model.addAttribute("roledetl",null);
    }










        ===================================
方法二    model.addObject("parentMenus", parentMenus);   ///////////////////////////////////////////////////////////////一个key,对应对个value
<c:forEach items="${parentMenus}" var="parent">
        <c:choose>
            <c:when test="${parent.isleaf=='0'}">
                <div class="titleArea_normal" ><i class="icon_spgl"></i>${parent.menuName}</div>
                <div class="box3" style="display: none">
                    <c:forEach items="${parent.childs}" var="item">
                        <c:choose>
                            <c:when test="${!empty item.url}">
                                <a class="list" href="${pageContext.request.contextPath}${item.url}" target="mainFrame"><span>${item.menuName}</span></a>
                            </c:when>
                            <c:otherwise>
                                <a   class="list" href="javascript:void(0)" target="mainFrame"><span>${item.menuName}</span></a>
                            </c:otherwise>
                        </c:choose>
                    </c:forEach>
                </div>

            </c:when>
            <c:when test="${parent.isleaf=='1'}">
                <a class="titleArea_normal  firstShow"  href="${pageContext.request.contextPath}${parent.url }" target="mainFrame"><i class="icon_home1"></i>${parent.menuName}<input type="hidden"/></a>
            </c:when>
        </c:choose>
    </c:forEach>
  
方法三 直接用@ResponseBody  结合ajax
  
  
隐藏域

页面a  var roles = "<a name='showMenu' href='${pageContext.request.contextPath}/system/users/userroles.do?id=" + lineData["id"] + "'  class='cyan'>【授用户组】</a>";

  String id = request.getParameter("id");
<%=id %>

隐藏域
@RequestMapping(value = "/userroles")
    public void checkbox( @RequestParam Long id ,Model model ) {
    model.addAttribute("id", id);

    }
<div>
<input id="userId" type="hidden" value="${id }">
</div>








Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326800830&siteId=291194637