[英]redirect to jsp page from spring controller
我是Spring MVC框架的新手。 我被困在某一點。 我想顯示當前jsp頁面中的另一個jsp頁面。為此,我在客戶端使用ajax。 我在下面共享我的代碼。 請幫我解決這個問題。 謝謝,
<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" />
您不需要ajax進行重定向。您可以直接使用
<a href="displayEditProfile" target="_blank">
<i class="glyphicon glyphicon-edit"></i>
Edit My Profile </a>
如果要傳遞一些參數,則可以使用action = displayEditProfile提交表單,並具有表單字段。
<form action="displayEditProfile" >
您必須刪除@ResponseBody。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.