spring页面转发和参数传递

                               
1.最简单的action页面提交和参数p的传递
     
        < form:form name = " batchForm "  method = " post "  action = " /video/list.html " >
       
< input type = " hidden "  name = " p "  value = " <c:out value= " $ {videoList.p} " /> " /> // 从action取得p的值
      </ form:form >
      
public  ModelAndView list(HttpServletRequest request,HttpServletResponse response)  {
        
int page = ServletRequestUtils.getIntParameter(request, "p"1);//通过超连接取得p的参数值
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put(
"p", page);
        
return new ModelAndView(listView, "videoList", map);
     }

2.在javascript里面实现不同连接的表单提交
 
< form id = " messageForm "  name = " messageForm "  method = " post "  onSubmit = " return
      onMessageFormSubmit(<c:out  value=
" $ {param.type} " />) " >  
       
< input type = " hidden "  name = " method "  value = " delete " />
       
< input type = " hidden "  name = " type "  value = " <c:out value= " $ {param.type} " /> "   />
    
</ form >
    
< script type = " text/javascript " >
        function onMessageFormSubmit(type) 
{
            
if(type == 0{
                document.messageForm.action 
= '/commend/special/list.html';
            }

            
if(type == 1){
                document.messageForm.action 
= '/special/list.html';
            }

         }

         Form.focusFirstElement($(
' messageForm ' ));
  
</ script >

3.通过编辑页面的提交给action="/special/edit.html"既对应的onsubmit方法返回给前一页面,注意删除按钮不应提交
 
< c:set var = " buttons " >
< input type = " submit "   class = " button "  name = " audited "  onclick = " bCancel=false "  value = " <fmt:message key
    =
" button.audited " /> " />
< input type = " button class= " button "  οnclick= " location.href = ' /special/list.html?method=find&from=edit '"
     value= " < fmt:message   key = " button.delete " /> " />
< input type = " submit "   class = " button "  name = " cancel "  onclick = " bCancel=true "  value = " <fmt:message
      key=
" button.back " /> " />
 
</ c:set >
 
< form:form commandName = " special "  method = " post "  action = " /special/edit.html "  id = " specialForm "   >
    
< input type = " hidden "  name = " type "  value = " <c:out value= " $ {param.type} "  /> "   />
    
< class = " buttonBar bottom " >
        
< c:out value = " ${buttons} "  escapeXml = " false "   />
    
</ p >
  
</ form:form >

4.jsp使用request.getAttribute()方法接收传递过来的special参数对象
  
   public  ModelAndView find(HttpServletRequest request,
            HttpServletResponse response) 
{
        
if (log.isDebugEnabled()) {
            log.debug(
"entering 'find' method...");
        }

        
int specialId = ServletRequestUtils.getIntParameter(request,
                
"specialId"-1);
        Special special 
= specialManager.findBySpecialId(specialId);
        
return new ModelAndView(findView, "special", special);
  }

    
<%
      
if ( null   ==  request.getAttribute( " special " ) )
        
{
    
%>
    
<script type="text/javascript">
    alert(
'<fmt:message key="special.status.conflict"/>');
     location.href
='/special/list.html?type=<%=ServletRequestUtils.getIntParameter(request, "type",0)%>
     &p=<%=ServletRequestUtils.getIntParameter(request, "p", 1)%>
';
    
</script>
     
<%     
        
return ;
    }
%>

5.此时的param是有controller传递过来的参数别名,即spring自带的参数.
   
< form:form commandName = " special "   method = " post "  id = " specialForm "  name = " specialForm "
     onsubmit
= " return  validateSpecial(this) " >
     
< input type = " hidden "  name = " type "  value = " <c:out value= " $ {param.type} "  /> "   />
      
< input type = " hidden "  name = " p "  value = " <c:out value= " $ {param.p} "  /> "   />
</ form:form >

6.通过controller传递参数,得到hashMap所封装的对象.
  
public  ModelAndView list(HttpServletRequest req, HttpServletResponse res)  {
    HashMap
<String,Object> videoRelationsMap = new HashMap<String,Object>();
        videoRelationsMap.put(
"video", video);
       
return new ModelAndView(view,"videoRelationsList",videoRelationsMap);
}

<%  Videos videos  =  (Videos)((HashMap)request.getAttribute( " videoRelationsList " )).get( " video " ); %>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值