免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
Spring MVC中redirect到一個(gè)頁(yè)面,同時(shí)帶些信息過(guò)去進(jìn)行顯示,但是不通過(guò)Se...

關(guān)鍵字: Spring   Spring MVC redirect Session URL    

如何在Spring MVC中redirect到一個(gè)頁(yè)面,同時(shí)帶些信息過(guò)去進(jìn)行顯示,但是不通過(guò)Session方式及URL方式?

想用跟正常的ModelAndView方式,但是用了RedirectView過(guò)去是拿不到的 ,如:

代碼
  1. new ModelAndView(new RedirectView("xxx.do"),"modelName",modelMap);    

只能用Session這種方式
代碼
  1. request.getSession().setAttribute("msg",map);   

或URL后面加信息
代碼
  1. new ModelAndView(new RedirectView("xxx.do?msg=xyz");   

然后在頁(yè)面獲取進(jìn)行顯示?

 

有沒(méi)有更好的方法?

11:45  |   永久鏈接  |   瀏覽 (4601)  |   評(píng)論  (9)  | Java   |   進(jìn)入論壇  | 
評(píng)論    共 9 條
sorphi    2006-09-20 13:08

cookie?

galaxystar    2006-09-20 13:08

內(nèi)部重新定向!用過(guò)濾器或者AOP,把當(dāng)前的request覆蓋掉要轉(zhuǎn)向的controller里的request,然后執(zhí)行那個(gè)controller,渲染頁(yè)面!
那個(gè)頁(yè)面就可以用你上一個(gè)controller里處理好的數(shù)據(jù)項(xiàng)了!(contriller里處理的atribute不能重名,否則就覆蓋掉了)

或者適當(dāng)改造spring mvc框架!

simbasun    2006-09-20 13:21

in your controller:

代碼
  1. new ModelAndView(new RedirectView("xxx.do"),"modelName",modelMap);    

 

then DispatcherServlet render the view with your modelMap:

代碼
  1. DispatcherServlet.render(ModelAndView mv, HttpServletRequest request, HttpServletResponse response){   
  2. ...   
  3. //call view's render method   
  4. view.render(mv.getModelInternal(), request, response);   
  5. }   
  6. ...   
  7.   
  8. AbstractView.render(Map model, HttpServletRequest request, HttpServletResponse response){   
  9. ...   
  10. //the model still here...   
  11. renderMergedOutputModel(mergedModel, request, response);   
  12. }   
  13.   
  14. RedirectView.renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response){   
  15. ...   
  16. //Append query properties to the redirect URL. Here, the modelMap represented by url...   
  17. appendQueryProperties(targetUrl, model, this.encodingScheme);   
  18.   
  19. //do redirect   
  20. sendRedirect(request, response, targetUrl.toString(), this.http10Compatible);   
  21. }  

 

沒(méi)有測(cè)試過(guò), 看了下spring mvc的source code.
從上面的代碼來(lái)看,

代碼
  1. new ModelAndView(new RedirectView("xxx.do"),"modelName",modelMap);    

是可以的...

 

你應(yīng)該Debug一下, 看看model在什么地方丟了...

simbasun    2006-09-20 14:15

做了個(gè)測(cè)試, 證明我上面的判斷是正確的...
而且也說(shuō)明了,為什么你的方法拿不到正確的值

代碼
  1. package com.simba.test;   
  2.   
  3. import java.util.HashMap;   
  4. import java.util.Map;   
  5.   
  6. import junit.framework.TestCase;   
  7.   
  8. import org.springframework.mock.web.MockHttpServletRequest;   
  9. import org.springframework.mock.web.MockHttpServletResponse;   
  10. import org.springframework.web.servlet.ModelAndView;   
  11. import org.springframework.web.servlet.view.RedirectView;   
  12.   
  13. public class TestRedirectView extends TestCase{   
  14.        
  15.     protected MockHttpServletRequest request = new MockHttpServletRequest("GET""");   
  16.     protected MockHttpServletResponse response = new MockHttpServletResponse();   
  17.   
  18.     public void testRedirect() throws Exception{   
  19.         Map<String, String> map = new HashMap<String, String>();   
  20.         map.put("key1""value1");   
  21.         map.put("key2""value2");   
  22.            
  23.         //這種用法,map就是ModelAndView中的Model.   
  24.         ModelAndView mv = new ModelAndView(new RedirectView("/foo/bar.jsp"), map);   
  25.            
  26.         //這里用getModel()與DispatcherServlet中用getModelInternal是一樣的.   
  27.         mv.getView().render(mv.getModel(), request, response);   
  28.            
  29.         assertEquals(response.getRedirectedUrl(),"/foo/bar.jsp?key1=value1&key2=value2");   
  30.     }   
  31.        
  32.     public void testWrongRedirect() throws Exception{   
  33.         Map<String, String> map = new HashMap<String, String>();   
  34.         map.put("key1""value1");   
  35.         map.put("key2""value2");   
  36.            
  37.         //這種用法,map就是ModelAndView中Model的一個(gè)key/value對(duì)了...   
  38.         ModelAndView mv = new ModelAndView(new RedirectView("/foo/bar.jsp"), "model", map);   
  39.            
  40.         //這里用getModel()與DispatcherServlet中用getModelInternal是一樣的.   
  41.         mv.getView().render(mv.getModel(), request, response);   
  42.            
  43.         assertTrue(response.getRedirectedUrl().contains("/foo/bar.jsp?model="));   
  44.     }   
  45. }   
  46.   

 

YuLimin    2006-09-20 14:52

也就是無(wú)論用有modelName或無(wú)modelName的方式傳遞給ModelAndView,這些值是有都轉(zhuǎn)化為URL進(jìn)行表示了,只不過(guò)在頁(yè)面上面無(wú)法通過(guò)通常的方式取得,如我用的JSTL 1.0.6標(biāo)簽:

代碼
  1. <c:out value='${modelName}'/>   
  2. <c:out value='${modelName.keyxxx}'/>   


代碼
  1. <c:out value='${keyxxx}'/>   

 

simbasun    2006-09-20 15:01

看到你的view才明白,你原來(lái)是想做這個(gè)...:)
這種情況下,你不應(yīng)該用redirect.
而應(yīng)該直接用 new ModelAndView("viewName",Model);

為什么一定要用redirect呢?

YuLimin    2006-09-20 16:09

區(qū)別在于F5不會(huì)現(xiàn)這個(gè)吧。

sorphi    2006-09-20 16:19

post and redirect
想要在兩個(gè)請(qǐng)求之間傳遞信息,除了session, url transfer之外,還有很多手段?。?
cookie
cache
database
file
...
就靠你權(quán)衡了

galaxystar    2006-09-20 16:51

表單重復(fù)提交的問(wèn)題,不能直接用model來(lái)傳了!只能用其他辦法!
html的問(wèn)題,沒(méi)辦法!

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶(hù)發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
SpringMVC源碼總結(jié)(十一)mvc:interceptors攔截器介紹
Spring MVC詳細(xì)源碼解析(下篇)
Spring MVC 4之ViewResolver視圖解析器
十天學(xué)會(huì)ASP之第九天
spring mvc中的頁(yè)面跳轉(zhuǎn)
當(dāng)點(diǎn)擊按鈕如何在asp.net 2.0中重新加載當(dāng)前的頁(yè)面
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服