2015-07-19 61 views
0

我是Spring MVC框架的新手。我被卡住了一點。我想從當前的jsp頁面顯示另一個jsp頁面,爲此我在客戶端使用ajax。我在下面分享我的代碼。請幫我解決這個問題。 謝謝,從彈簧控制器重定向到jsp頁面

<li> 
            <a href="" onclick="displayEditProfile();" target="_blank"> 
             <i class="glyphicon glyphicon-edit"></i> 
             Edit My Profile </a> 
           </li> 

我的JavaScript函數:

function displayEditProfile(){ 
$.ajax({ 
    url: '/HappyWorld/displayEditProfile.do', 
    data:{ 
     //sharePost : $('#userPost').val(), 
     //"password":$('#passwordId').val(), 
     time : new Date(), 
    }, 
    type: 'GET', 
    dataType: 'text', 

    success: function(data) { 

    }, 
error: function(xhr, textStatus, errorThrown) { 
    alert(xhr+" "+textStatus+" "+errorThrown); 
} 
}); 

}

我的控制器:

@RequestMapping(value="/displayEditProfile", method = RequestMethod.GET) 
@ResponseBody 
public ModelAndView displayEditProfile(HttpServletRequest request,HttpServletResponse response) { 
    System.out.println(" in call."); 
    return new ModelAndView("edit_user_profile"); 

} 

和我的觀點xml配置是:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/jsp/" p:suffix=".jsp" /> 
+0

但爲什麼ajax要實現這個目標? – KDP

+0

所以我該怎麼做? –

+0

檢查我的以下答案 – KDP

回答

1

,如果你想傳遞一些參數,你可以用行動= displayEditProfile提交表單,並有表單字段你不需要阿賈克斯redirect.You可以直接使用

 <a href="displayEditProfile" target="_blank"> 
      <i class="glyphicon glyphicon-edit"></i> 
            Edit My Profile </a> 

<form action="displayEditProfile" > 
0

您必須刪除@ResponseBody。